Difference between revisions of "Tutorial:Measuring distances, angles, dihedrals"
From MSL-Libraries
Jump to navigationJump to searchLine 72: | Line 72: | ||
fprintf(stdout, "%-15s = %8.3f\n","Point Angle",angleDegrees); | fprintf(stdout, "%-15s = %8.3f\n","Point Angle",angleDegrees); | ||
fprintf(stdout, "%-15s = %8.3f\n","Point Dihedral",dihedralDegrees); | fprintf(stdout, "%-15s = %8.3f\n","Point Dihedral",dihedralDegrees); | ||
+ | |||
+ | |||
+ | // Get specific dihedrals... Phi/Psi of alpha amino acid proteins | ||
+ | |||
+ | // First create a System object | ||
+ | System sys; | ||
+ | sys.addAtoms(atoms.getAtomPointers()); | ||
+ | |||
+ | cout << endl << endl << "Phi-Psi of residue "<<sys.getResidue(1).toString()<<endl; | ||
+ | |||
+ | double phi = PhiPsiStatistics::getPhi(sys.getResidue(0), sys.getResidue(1)); | ||
+ | double psi = PhiPsiStatistics::getPsi(sys.getResidue(1), sys.getResidue(2)); | ||
+ | |||
+ | fprintf(stdout,"\tPHI: %8.3f\n\tPSI: %8.3f\n",phi,psi); | ||
+ | |||
+ | |||
</source> | </source> | ||
Latest revision as of 02:55, 10 April 2010
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);
// Get specific dihedrals... Phi/Psi of alpha amino acid proteins
// First create a System object
System sys;
sys.addAtoms(atoms.getAtomPointers());
cout << endl << endl << "Phi-Psi of residue "<<sys.getResidue(1).toString()<<endl;
double phi = PhiPsiStatistics::getPhi(sys.getResidue(0), sys.getResidue(1));
double psi = PhiPsiStatistics::getPsi(sys.getResidue(1), sys.getResidue(2));
fprintf(stdout,"\tPHI: %8.3f\n\tPSI: %8.3f\n",phi,psi);
}