/*************************************************************************** molalgo.cpp - description ------------------- begin : Tue Nov 18 01:45:35 2003 copyright : (C) 1999-2006 by Cavalli Andrea author : : cavalli $ date : : 2003/12/09 11:10:33 $ id : : coor.h,v 1.1.2.2 2003/12/09 11:10:33 cavalli Exp $ email : cavalli@bioc.unizh.ch amc82@cam.ac.uk **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef __MOLALGO__ #define __MOLALGO__ #include #include #include #include #include #include #include #include #include #include extern "C" { int nsc_dclm( double * , /* atom coordinates xyz0, xyz1, ... */ double * , /* atom radii r0, r1, r2, ... */ int , /* number of atoms */ int , /* number of dots per fully accessible sphere */ int , /* flag : dots, volume and/or area per atom */ double * , /* 1 output: overall area */ double ** , /* 2 output: pointer to list of areas per atom */ double * , /* 3 output: overall volume */ double ** , /* 4 output: pointer to list of surface dots x0, y0, z0, ... */ int * /* 5 output: number of surface dots */ ); } #define FLAG_DOTS 01 #define FLAG_VOLUME 02 #define FLAG_ATOM_AREA 04 namespace Almost { //Solvate void boxsolvate(const Protein & p, const Solvent & wat, double t, string file){ //Compute BB of protein if(p.atom_size()==0){ cout<<"\t>> Protein is empty: nothing to solvate!!"<max[0]) max[0] = p[i][0]; if(p[i][1]>max[1]) max[1] = p[i][1]; if(p[i][2]>max[2]) max[2] = p[i][2]; if(p[i][0]> Generating box of size:\n" <<"\t "<wmax[0]) wmax[0] = wat[i][0]; if(wat[i][1]>wmax[1]) wmax[1] = wat[i][1]; if(wat[i][2]>wmax[2]) wmax[2] = wat[i][2]; if(wat[i][0]> Water box of size:\n" <<"\t "<> Construncting water grid of size: \n" <<"\t "<> FATAL ERROR: WATER is not of type TIP3P!\n"; return; } vector remove; remove.resize(nwat); int atom_counter = 0; for(int i=0;imax[0]-1)|| (tip[a][1]>max[1]-1)|| (tip[a][2]>max[2]-1)){ remove[i] = 1; // cout<<"BOX size exceded "<> "<> Protein is empty: nothing to solvate!!"<R2) R2=d2; } R = sqrt(R2)+t; R2 = R*R; double max[3],min[3],wmax[3],wmin[3]; max[0] = com[0]+R; max[1] = com[1]+R; max[2] = com[2]+R; min[0] = com[0]-R; min[1] = com[1]-R; min[2] = com[2]-R; cout<<"\t>> Generating box on size:\n" <<"\t "<wmax[0]) wmax[0] = wat[i][0]; if(wat[i][1]>wmax[1]) wmax[1] = wat[i][1]; if(wat[i][2]>wmax[2]) wmax[2] = wat[i][2]; if(wat[i][0]> Water box on size:\n" <<"\t "<> Construncting water grid of size: \n" <<"\t "<> FATAL ERROR: WATER is not of type TIP3P!\n"; return 0; } vector remove; remove.resize(nwat); int atom_counter = 0; for(int i=0;imax[0]-1)|| (tip[a][1]>max[1]-1)|| (tip[a][2]>max[2]-1)){ remove[i] = 1; // cout<<"BOX size exceded "<R2){ remove[i] = 1; break;} } atom_counter +=3; } atom_counter = 0; for(int i=0;i> Protein is empty: nothing to solvate!!"<R2) R2=d2; } R = sqrt(R2)+t; R2 = R*R; double max[3],min[3],wmax[3],wmin[3]; max[0] = com[0]+R; max[1] = com[1]+R; max[2] = com[2]+R; min[0] = com[0]-R; min[1] = com[1]-R; min[2] = com[2]-R; cout<<"\t>> Generating box on size:\n" <<"\t "<wmax[0]) wmax[0] = wat[i][0]; if(wat[i][1]>wmax[1]) wmax[1] = wat[i][1]; if(wat[i][2]>wmax[2]) wmax[2] = wat[i][2]; if(wat[i][0]> Water box on size:\n" <<"\t "<> Construncting water grid of size: \n" <<"\t "<> FATAL ERROR: WATER is not of type TIP3P!\n"; return; } vector remove; remove.resize(nwat); int atom_counter = 0; for(int i=0;imax[0]-1)|| (tip[a][1]>max[1]-1)|| (tip[a][2]>max[2]-1)){ remove[i] = 1; // cout<<"BOX size exceded "<R2){ remove[i] = 1; break;} } atom_counter +=3; } atom_counter = 0; for(int i=0;i0){ remove[i] = 1;} atom_counter += 3; } //writr PDB ofstream pdb; pdb.open(file.c_str()); atom_counter = 0; int natom = 0; int nfrag = 0; int removed = 0; for(int i=0;i> Moecules are empty: nothing to solvate!!"<R2) R2=d2; } R = sqrt(R2)+t; R2 = R*R; double max[3],min[3],wmax[3],wmin[3]; max[0] = com[0]+R; max[1] = com[1]+R; max[2] = com[2]+R; min[0] = com[0]-R; min[1] = com[1]-R; min[2] = com[2]-R; cout<<"\t>> Generating box on size:\n" <<"\t "<wmax[0]) wmax[0] = wat[i][0]; if(wat[i][1]>wmax[1]) wmax[1] = wat[i][1]; if(wat[i][2]>wmax[2]) wmax[2] = wat[i][2]; if(wat[i][0]> Water box on size:\n" <<"\t "<> Construncting water grid of size: \n" <<"\t "<> FATAL ERROR: WATER is not of type TIP3P!\n"; return; } vector remove; remove.resize(nwat); int atom_counter = 0; for(int i=0;imax[0]-1)|| (tip[a][1]>max[1]-1)|| (tip[a][2]>max[2]-1)){ remove[i] = 1; // cout<<"BOX size exceded "<R2){ remove[i] = 1; break;} } atom_counter +=3; } atom_counter = 0; for(int i=0;i0){ remove[i] = 1;} atom_counter += 3; } //writr PDB ofstream pdb; pdb.open(file.c_str()); atom_counter = 0; int natom = 0; int nfrag = 0; int removed = 0; for(int i=0;i> Moleculs empty: nothing to solvate!!"<R2) R2=d2; } R = sqrt(R2)+t; R2 = R*R; double max[3],min[3],wmax[3],wmin[3]; max[0] = com[0]+R; max[1] = com[1]+R; max[2] = com[2]+R; min[0] = com[0]-R; min[1] = com[1]-R; min[2] = com[2]-R; cout<<"\t>> Generating box on size:\n" <<"\t "<wmax[0]) wmax[0] = wat[i][0]; if(wat[i][1]>wmax[1]) wmax[1] = wat[i][1]; if(wat[i][2]>wmax[2]) wmax[2] = wat[i][2]; if(wat[i][0]> Water box on size:\n" <<"\t "<> Construncting water grid of size: \n" <<"\t "<> FATAL ERROR: WATER is not of type TIP3P!\n"; return 0; } vector remove; remove.resize(nwat); int atom_counter = 0; for(int i=0;imax[0]-1)|| (tip[a][1]>max[1]-1)|| (tip[a][2]>max[2]-1)){ remove[i] = 1; // cout<<"BOX size exceded "<R2){ remove[i] = 1; break;} } atom_counter +=3; } atom_counter = 0; for(int i=0;i c1(m1); Coor c2(m2); double rmsd = rmsd_mat(c1,c2,s.result(),r); //check selection !!!! //now rotate for(int i=0;i<3;i++) cog[i] = cog1[i] = 0; set::iterator iter = s.result().begin(), end = s.result().end(); size = s.result().size(); while(iter!=end){ int pos = (*iter)*Coor::DIM; cog[0] += c2.coor[pos]; cog[1] += c2.coor[pos+1]; cog[2] += c2.coor[pos+2]; cog1[0] += c1.coor[pos]; cog1[1] += c1.coor[pos+1]; cog1[2] += c1.coor[pos+2]; ++iter; } for(int i=0;i<3;i++) cog[i] /= size; for(int i=0;i<3;i++) cog1[i] /= size; for(int i=0;i::DIM; c2.coor[pos] -= cog[0]; c2.coor[pos+1] -= cog[1]; c2.coor[pos+2] -= cog[2]; } for(int i=0;i::DIM; c1.coor[pos] = r[0][0]*c2.coor[pos] + r[0][1]*c2.coor[pos+1] + r[0][2]*c2.coor[pos+2]; c1.coor[pos+1] = r[1][0]*c2.coor[pos] + r[1][1]*c2.coor[pos+1] + r[1][2]*c2.coor[pos+2]; c1.coor[pos+2] = r[2][0]*c2.coor[pos] + r[2][1]*c2.coor[pos+1] + r[2][2]*c2.coor[pos+2]; } for(int i=0;i::DIM; c1.coor[pos] += cog1[0]; c1.coor[pos+1] += cog1[1]; c1.coor[pos+2] += cog1[2]; } for(int i=0;i::DIM; //assign m2[i][0] = c1.coor[pos]; m2[i][1] = c1.coor[pos+1]; m2[i][2] = c1.coor[pos+2]; } return rmsd; } double fit2(const Molecules & m1, Molecules & m2, const NameSelection &s1, const NameSelection &s2){ int size; double r[3][3],cog[3],cog1[3]; Coor c1(m1); Coor c2(m2); if(s1.result().size()!=s2.result().size()){ cout<<"\t>> Can't fit molecules with selections of different size " <::iterator iter = s2.result().begin(), end = s2.result().end(); size = s1.result().size(); while(iter!=end){ int pos = (*iter)*Coor::DIM; cog[0] += c2.coor[pos]; cog[1] += c2.coor[pos+1]; cog[2] += c2.coor[pos+2]; ++iter; } iter = s1.result().begin(); end = s1.result().end(); while(iter!=end){ int pos = (*iter)*Coor::DIM; cog1[0] += c1.coor[pos]; cog1[1] += c1.coor[pos+1]; cog1[2] += c1.coor[pos+2]; ++iter; } for(int i=0;i<3;i++) cog[i] /= size; for(int i=0;i<3;i++) cog1[i] /= size; for(int i=0;i::DIM; c2.coor[pos] -= cog[0]; c2.coor[pos+1] -= cog[1]; c2.coor[pos+2] -= cog[2]; } c1.resize(c2.size()); for(int i=0;i::DIM; c1.coor[pos] = r[0][0]*c2.coor[pos] + r[0][1]*c2.coor[pos+1] + r[0][2]*c2.coor[pos+2]; c1.coor[pos+1] = r[1][0]*c2.coor[pos] + r[1][1]*c2.coor[pos+1] + r[1][2]*c2.coor[pos+2]; c1.coor[pos+2] = r[2][0]*c2.coor[pos] + r[2][1]*c2.coor[pos+1] + r[2][2]*c2.coor[pos+2]; } for(int i=0;i::DIM; c1.coor[pos] += cog1[0]; c1.coor[pos+1] += cog1[1]; c1.coor[pos+2] += cog1[2]; } for(int i=0;i::DIM; //assign m2[i][0] = c1.coor[pos]; m2[i][1] = c1.coor[pos+1]; m2[i][2] = c1.coor[pos+2]; } return rmsd; } double fit2_coor(const Coor & c1, Coor & c2, const NameSelection &s1, const NameSelection &s2){ int size; double r[3][3],cog[3],cog1[3]; // Coor c1(m1); // Coor c2(m2); if(s1.result().size()!=s2.result().size()){ cout<<"\t>> Can't fit molecules with selections of different size " <::iterator iter = s2.result().begin(), end = s2.result().end(); size = s1.result().size(); while(iter!=end){ int pos = (*iter)*Coor::DIM; cog[0] += c2.coor[pos]; cog[1] += c2.coor[pos+1]; cog[2] += c2.coor[pos+2]; ++iter; } iter = s1.result().begin(); end = s1.result().end(); while(iter!=end){ int pos = (*iter)*Coor::DIM; cog1[0] += c1.coor[pos]; cog1[1] += c1.coor[pos+1]; cog1[2] += c1.coor[pos+2]; ++iter; } for(int i=0;i<3;i++) cog[i] /= size; for(int i=0;i<3;i++) cog1[i] /= size; for(int i=0;i::DIM; c2.coor[pos] -= cog[0]; c2.coor[pos+1] -= cog[1]; c2.coor[pos+2] -= cog[2]; } Coor c_tmp; c_tmp.resize(c2.size()); for(int i=0;i::DIM; c_tmp.coor[pos] = r[0][0]*c2.coor[pos] + r[0][1]*c2.coor[pos+1] + r[0][2]*c2.coor[pos+2]; c_tmp.coor[pos+1] = r[1][0]*c2.coor[pos] + r[1][1]*c2.coor[pos+1] + r[1][2]*c2.coor[pos+2]; c_tmp.coor[pos+2] = r[2][0]*c2.coor[pos] + r[2][1]*c2.coor[pos+1] + r[2][2]*c2.coor[pos+2]; } for(int i=0;i::DIM; c_tmp.coor[pos] += cog1[0]; c_tmp.coor[pos+1] += cog1[1]; c_tmp.coor[pos+2] += cog1[2]; } for(int i=0;i::DIM; //assign c2.coor[pos] = c_tmp.coor[pos]; c2.coor[pos+1] = c_tmp.coor[pos+1]; c2.coor[pos+2] = c_tmp.coor[pos+2]; } return rmsd; } double mfit(const Molecules & m1, Molecules & m2, const NameSelection &s, const MDB & mdb){ double r[3][3],com[3],com1[3]; int size = s.result().size(); double * mass = new double[size]; double *mass_sqrt = new double[size]; double M; { set::iterator iter = s.result().begin(), end = s.result().end(); int count = 0; M = 0; while(iter!=end){ mass[count] = mdb.atomT(m1[*iter].type_name()).mass(); M += mass[count]; ++count; ++iter; } iter = s.result().begin(); count = 0; while(iter!=end){ mass_sqrt[count] = sqrt(mass[count]); ++count; ++iter; } } Coor c1(m1); Coor c2(m2); //check selection !!!! //now rotate for(int i=0;i<3;i++) com[i] = com1[i] = 0; set::iterator iter = s.result().begin(), end = s.result().end(); double * mp = mass; while(iter!=end){ int pos = (*iter)*Coor::DIM; com[0] += (*mp)*c2.coor[pos]; com[1] += (*mp)*c2.coor[pos+1]; com[2] += (*mp)*c2.coor[pos+2]; com1[0] += (*mp)*c1.coor[pos]; com1[1] += (*mp)*c1.coor[pos+1]; com1[2] += (*mp)*c1.coor[pos+2]; ++mp; ++iter; } for(int i=0;i<3;i++) com[i] /= M; for(int i=0;i<3;i++) com1[i] /= M; for(int i=0;i::DIM; c2.coor[pos] -= com[0]; c2.coor[pos+1] -= com[1]; c2.coor[pos+2] -= com[2]; c1.coor[pos] -= com1[0]; c1.coor[pos+1] -= com1[1]; c1.coor[pos+2] -= com1[2]; } double rmsd = mrmsd_mat(c1,c2,s.result(),mass_sqrt,r); for(int i=0;i::DIM; c1.coor[pos] = r[0][0]*c2.coor[pos] + r[0][1]*c2.coor[pos+1] + r[0][2]*c2.coor[pos+2]; c1.coor[pos+1] = r[1][0]*c2.coor[pos] + r[1][1]*c2.coor[pos+1] + r[1][2]*c2.coor[pos+2]; c1.coor[pos+2] = r[2][0]*c2.coor[pos] + r[2][1]*c2.coor[pos+1] + r[2][2]*c2.coor[pos+2]; } for(int i=0;i::DIM; c1.coor[pos] += com1[0]; c1.coor[pos+1] += com1[1]; c1.coor[pos+2] += com1[2]; } for(int i=0;i::DIM; //assign m2[i][0] = c1.coor[pos]; m2[i][1] = c1.coor[pos+1]; m2[i][2] = c1.coor[pos+2]; } delete [] mass; delete [] mass_sqrt; return sqrt(size/M)*rmsd; } void rmsd_prof(const Molecules & m1, Molecules & m2,string file){ ofstream out; out.open(file.c_str()); for(int i=0;i a = m1.fragment_atoms(i); double d2 = 0; for(int j=0;j c1(m1); Coor c2(m2); set::iterator iter = s2.result().begin(), end = s2.result().end(); double rmsd = 0; while(iter!=end){ int pos = *iter; pos = Coor::DIM*pos; double dx = c1.coor[pos] - c2.coor[pos]; double dy = c1.coor[pos+1] - c2.coor[pos+1]; double dz = c1.coor[pos+2] - c2.coor[pos+2]; rmsd += dx*dx+dy*dy+dz*dz; ++iter; } return sqrt(rmsd/s2.result().size()); } void set_torsion(Protein & protein, int s1, int s2, int s3, int s4, double tor){ BondRotation bond_rotation(protein); vector coor; for(int i= protein.atom_offset(); i(protein[i].coor())); bond_rotation.set_dihedral(coor,s1,s2,s3,s4,tor); } void set_torsion2(Protein & protein, int s1, int s2, int s3, int s4, double tor, BondRotation & bond_rotation ){ vector coor; for(int i= protein.atom_offset(); i(protein[i].coor())); bond_rotation.set_dihedral(coor,s1,s2,s3,s4,tor); } double ramadist(double phi1, double psi1, double phi2, double psi2){ double d1 = abs(phi1-phi2); double t; t = abs(phi1-phi2+360); if(t phi1,psi1,phi2,psi2; phi1 = p1.phi(); phi2 = p2.phi(); psi1 = p1.psi(); psi2 = p2.psi(); if(phi1.size()!=phi2.size()) return -1; int size = phi1.size(); double todeg = (180.0/M_PI); for(int i=0;i> " <> Good ramachandran amino-acids: "<<(100.0*g)/c< phi = p.phi(); vector psi = p.psi(); for(int i=0;i br(p); vector N; vector C; vector CA; int b = p.atom_offset(); int e = p.atom_size()+p.atom_offset(); for(int i = b; i phi = p.phi(); vector psi = p.psi(); for(int i=0;i br(p); vector N; vector C; vector CA; int b = p.atom_offset(); int e = p.atom_size()+p.atom_offset(); for(int i = b; i c1(mols); return calc_rgyr(c1,s.result()); } void render_tachyon(const Molecules & m, string file){ ofstream dat; dat.open(file.c_str()); vector vdw; for(int i=0;i> Steric clash "< cysd; for(int i=0;i