int main(int argc, char *argv[]){
    
	// Option Parser
        Options opt = setupOptions(argc,argv);

	// Read PDB
	System sys;
	sys.readPdb(opt.pdb);

	int centerResidueIndex = -1;
	for (uint i = 0; i < sys.positionSize();i++){
		if ((sys.getPosition(i).getResidueNumber() == opt.resnum) && (sys.getPosition(i).getChainId() == opt.chain)) {
			centerResidueIndex = i;
			break;
		}
	}
	if (centerResidueIndex == -1){
		cerr << "ERROR Couldn't find central residue"<<endl;
		cerr << opt.pdb << endl;
		cerr << opt.resnum << "\t" << opt.chain << endl;
		exit(3);
	}
	cout << "Compute Frame.h"<<endl;
 	Frame f;
	if (!f.computeFrameFromFunctionalGroup(sys.getPosition(centerResidueIndex).getCurrentIdentity())){
			cerr << "Problem creating frame from central residue"<<endl;
			cerr << opt.pdb << endl;
			cerr << opt.resnum << "\t" << opt.chain << endl;
			exit(324);
	}

	if (opt.printFrames){
		cout << "Write out basic frame"<<endl;
		ofstream fout;
		fout.open("basicFrame.py");
		fout << f.toString()<<endl;
		fout.close();
	}


	// Align frame and atoms of sys to origin.
	AtomPointerVector &av = sys.getAtomPointers();
	f.transformToGlobalBasis(av);


	Transforms t;
	for (uint i = 0; i < sys.positionSize();i++){
		if (i == centerResidueIndex) continue;
		Residue &r  = sys.getResidue(i);
		CartesianPoint cp;

		double angleBetweenFrames = MslTools::doubleMax;
		if (r.getResidueName() == "ASP" &&
			    r.atomExists("CG") &&
			    r.atomExists("OD1") &&
			    r.atomExists("OD2")){
				
				cp.setCoor( (r("CG").getX()+r("OD1").getX()+r("OD2").getX()) / 3, 
					    (r("CG").getY()+r("OD1").getY()+r("OD2").getY()) / 3, 
					    (r("CG").getZ()+r("OD1").getZ()+r("OD2").getZ()) / 3);


				if (i != centerResidueIndex) {

					f.transformFromGlobalBasis(r.getAtomPointers());

					Frame floatingFrame;
					floatingFrame.computeFrameFrom3Atoms(r("OD1"),r("CG"),r("OD2"));

					if (opt.printFrames){

						
						char name[80];
						sprintf(name,"aspFrame%1s%03d.py",r.getChainId().c_str(),r.getResidueNumber());

						ofstream fout;
						fout.open(name);
						fout << floatingFrame.toString()<<endl;
						fout.close();
					}



					//cout << floatingFrame.toString()<<endl;

					Matrix m = f.anglesBetweenFrame(floatingFrame);
					angleBetweenFrames = m[2][2];// z vs z

					f.transformToGlobalBasis(r.getAtomPointers());

				}
				
		}

		if (r.getResidueName() == "ASN" &&
			    r.atomExists("CG") &&
			    r.atomExists("OD1") &&
			    r.atomExists("ND2")){
				
				cp.setCoor( (r("CG").getX()+r("OD1").getX()+r("ND2").getX()) / 3, 
					    (r("CG").getY()+r("OD1").getY()+r("ND2").getY()) / 3, 
					    (r("CG").getZ()+r("OD1").getZ()+r("ND2").getZ()) / 3);



				if (i != centerResidueIndex) {
					f.transformFromGlobalBasis(r.getAtomPointers());
					Frame floatingFrame;
					floatingFrame.computeFrameFrom3Atoms(r("OD1"),r("CG"),r("ND2"));

					if (opt.printFrames){
						char name[80];
						sprintf(name,"asnFrame%1s%03d.py",r.getChainId().c_str(),r.getResidueNumber());

						ofstream fout;
						fout.open(name);
						fout << floatingFrame.toString()<<endl;
						fout.close();
					}

					Matrix m = f.anglesBetweenFrame(floatingFrame);
					angleBetweenFrames = m[2][2];// z vs z
					f.transformToGlobalBasis(r.getAtomPointers());
				}
				
		}


		if (r.getResidueName() == "GLU" &&
			    r.atomExists("CD") &&
			    r.atomExists("OE1") &&
			    r.atomExists("OE2")){
				
				cp.setCoor( (r("CD").getX()+r("OE1").getX()+r("OE2").getX()) / 3, 
					    (r("CD").getY()+r("OE1").getY()+r("OE2").getY()) / 3, 
					    (r("CD").getZ()+r("OE1").getZ()+r("OE2").getZ()) / 3);



				if (i != centerResidueIndex) {
					f.transformFromGlobalBasis(r.getAtomPointers());
					Frame floatingFrame;
					floatingFrame.computeFrameFrom3Atoms(r("OE1"),r("CD"),r("OE2"));

					if (opt.printFrames){
						char name[80];
						sprintf(name,"gluFrame%1s%03d.py",r.getChainId().c_str(),r.getResidueNumber());

						ofstream fout;
						fout.open(name);
						fout << floatingFrame.toString()<<endl;
						fout.close();
					}

					Matrix m = f.anglesBetweenFrame(floatingFrame);
					angleBetweenFrames = m[2][2];// z vs z
					f.transformToGlobalBasis(r.getAtomPointers());
				}
				
		}

		if (r.getResidueName() == "GLN" &&
			    r.atomExists("CD") &&
			    r.atomExists("OE1") &&
			    r.atomExists("NE2")){
				
				cp.setCoor( (r("CD").getX()+r("OE1").getX()+r("NE2").getX()) / 3, 
					    (r("CD").getY()+r("OE1").getY()+r("NE2").getY()) / 3, 
					    (r("CD").getZ()+r("OE1").getZ()+r("NE2").getZ()) / 3);


				if (i != centerResidueIndex) {
					f.transformFromGlobalBasis(r.getAtomPointers());
					Frame floatingFrame;
					floatingFrame.computeFrameFrom3Atoms(r("OE1"),r("CD"),r("NE2"));
					if (opt.printFrames){
						char name[80];
						sprintf(name,"glnFrame%1s%03d.py",r.getChainId().c_str(),r.getResidueNumber());

						ofstream fout;
						fout.open(name);
						fout << floatingFrame.toString()<<endl;
						fout.close();
					}

					Matrix m = f.anglesBetweenFrame(floatingFrame);
					angleBetweenFrames = m[2][2];// z vs z
					f.transformToGlobalBasis(r.getAtomPointers());
				}

				
		}

		
		SphericalPoint spRes = t.transform(cp);
		if (angleBetweenFrames == MslTools::doubleMax){
			angleBetweenFrames = 0;
		} else {
			if (angleBetweenFrames > 90){
				angleBetweenFrames = 180 - angleBetweenFrames;
			}

		}

 		fprintf(stdout, "RES %10s %1s %04d %3s %8.3f %8.3f %8.3f %8.3f\n",MslTools::getFileName(opt.pdb).c_str(),r.getChainId().c_str(),r.getResidueNumber(),r.getResidueName().c_str(),spRes.getRadius(), spRes.getSigma(),spRes.getTheta(),angleBetweenFrames*M_PI/180);


		AtomPointerVector &ats = r.getAtomPointers();
		for (uint j = 0; j < ats.size();j++){
			SphericalPoint sp = t.transform(ats(j).getCoor());
			
			//fprintf(stdout, "ATM %10s %1s %04d %3s %4s %8.3f %8.3f %8.3f\n",MslTools::getFileName(opt.pdb).c_str(),ats(j).getChainId().c_str(),ats(j).getResidueNumber(),r.getResidueName().c_str(),ats(j).getName().c_str(),sp.getRadius(), sp.getSigma(),sp.getTheta());
			Residue &cent = sys.getPosition(centerResidueIndex).getCurrentIdentity();
 			if (cent.getResidueName() == "LYS"){
	 			double lysDihedral = 0;
 				double lysAngle    = 0;
 				lysDihedral = cent("CD").getCoor().dihedral(cent("CE").getCoor(),cent("NZ").getCoor(),ats(j).getCoor());
 				lysAngle    = cent("CE").getCoor().angle(cent("NZ").getCoor(),ats(j).getCoor());
				fprintf(stdout, "ATM %10s %04d %1s %04d %3s %4s %8.3f %8.3f %8.3f %8.3f %8.3f\n",MslTools::getFileName(opt.pdb).c_str(),opt.resnum,ats(j).getChainId().c_str(),ats(j).getResidueNumber(),r.getResidueName().c_str(),ats(j).getName().c_str(),sp.getRadius(), sp.getSigma(),sp.getTheta(),lysAngle,lysDihedral);
 			}
			else {
				// JEDONALD WAY..
				fprintf(stdout, "ATM %10s %04d %1s %04d %3s %4s %8.3f %8.3f %8.3f %8.3f\n",MslTools::getFileName(opt.pdb).c_str(),opt.resnum,ats(j).getChainId().c_str(),ats(j).getResidueNumber(),r.getResidueName().c_str(),ats(j).getName().c_str(),sp.getRadius(), sp.getSigma(),sp.getTheta(), angleBetweenFrames*M_PI/180);
			}
		}

		
	}
	
		
	cout << "Done."<<endl;
}
Пример #2
0
Point::Point(const SphericalPoint & sp) :
		x(sp.getRadius() * (sin(sp.getTheta().getValue()) * cos(sp.getPhi().getValue()))), y(
				sp.getRadius() * (sin(sp.getTheta().getValue()) * sin(sp.getPhi().getValue()))), z(
				sp.getRadius() * cos(sp.getTheta().getValue())) {
}