Tutorial:Measuring distances, angles, dihedrals

From MSL-Libraries
Revision as of 02:29, 10 April 2010 by Dwkulp (talk | contribs)
Jump to navigationJump to search

Tutorial writing in progress, errors may exist

This is an example on how to measure distances, angles and dihedrals (Includes wrapper functions for measuring Phi/Psi/Chi angles).


Complete source of example_measurements.cpp


To compile

% make bin/example_measurements

To run the program

Go to the main directory and run the command (note, the location of the exampleFiles subdirectory needs to be provided as an argument)

% bin/example_molecular_measurements exampleFiles

Program description

	string refFile = "example0005.pdb";
	refFile = (string)argv[1] + "/" + refFile;

	AtomContainer atoms;
	if (!atoms.readPdb(refFile)) {
		cerr << endl;
		cerr << "File " << refFile << " cannot be found, please speficy the path of the \"exampleFiles\" directory as an argument" << endl;
		exit(1);
	}


	// Distance and Distance Squared bewteen two atoms atoms[0] and atoms[size()-1]   (first and last atom)
	double distance        = atoms[0].distance(atoms[atoms.size()-1]);
	double distanceSquared = atoms[0].distance2(atoms[atoms.size()-1]);

	// Angle between three atoms ( atoms[0] - atoms[1] - atoms[2] angle)
	double angleDegrees    = atoms[0].angle(atoms[1],atoms[2]);
	double angleRadians    = atoms[0].angleRadians(atoms[1],atoms[2]);
	

	// Dihedral between four atoms ( atoms[0] - atoms[1] - atoms[2] - atoms[3] )
	double dihedralDegrees    = atoms[0].dihedral(atoms[1],atoms[2],atoms[3]);
	double dihedralRadians    = atoms[0].dihedralRadians(atoms[1],atoms[2],atoms[3]);
	
	
	// Print out measurements
	fprintf(stdout, "%-15s = %8.3f\n","Distance",distance);
	fprintf(stdout, "%-15s = %8.3f\n","DistanceSquared",distanceSquared);
	fprintf(stdout, "%-15s = %8.3f\n","AngleDegrees",angleDegrees);
	fprintf(stdout, "%-15s = %8.3f\n","AngleRadians",angleRadians);
	fprintf(stdout, "%-15s = %8.3f\n","DihedralDegrees",dihedralDegrees);
	fprintf(stdout, "%-15s = %8.3f\n","DihedralRadians",dihedralRadians);


	// Measurement Namespace : CartesianGeometry


	// The above Atom-based functions are wrappers to the utility functions in the CartesianGeometry namespace.

	CartesianPoint pt1(0.0 , 0.0 , 0.0);
	CartesianPoint pt2(1.0 , 0.0 , 0.0);
	CartesianPoint pt3(1.0 , 1.0 , 0.0);
	CartesianPoint pt4(1.0 , 1.0 , 1.0);

	distance        = CartesianGeometry::distance(pt1,pt2);
	angleDegrees    = CartesianGeometry::angle(pt1,pt2,pt3);
	dihedralDegrees = CartesianGeometry::dihedral(pt1,pt2,pt3,pt4);

	cout << endl;

	fprintf(stdout, "%-15s = %8.3f\n","Point Distance",distance);
	fprintf(stdout, "%-15s = %8.3f\n","Point Angle",angleDegrees);
	fprintf(stdout, "%-15s = %8.3f\n","Point Dihedral",dihedralDegrees);


}



Back to the tutorial page