LigandDroplet.h

Go to the documentation of this file.
00001 /* -------------------------------------------------------------------------- *
00002  *                      SimTK Core: SimTK Molmodel                            *   
00003  * -------------------------------------------------------------------------- *
00004  * This is part of the SimTK Core biosimulation toolkit originating from      *   
00005  * Simbios, the NIH National Center for Physics-Based Simulation of           *   
00006  * Biological Structures at Stanford, funded under the NIH Roadmap for        *   
00007  * Medical Research, grant U54 GM072970. See https://simtk.org.               *   
00008  *                                                                            *   
00009  * Portions copyright (c) 2008 Stanford University and the Authors.           *   
00010  * Authors: Samuel Flores                                                     *   
00011  * Contributors: Christopher Bruns, Peter Eastman                             *   
00012  *                                                                            *   
00013  * Permission is hereby granted, free of charge, to any person obtaining a    *   
00014  * copy of this software and associated documentation files (the "Software"), *
00015  * to deal in the Software without restriction, including without limitation  *
00016  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *   
00017  * and/or sell copies of the Software, and to permit persons to whom the      *   
00018  * Software is furnished to do so, subject to the following conditions:       *   
00019  *                                                                            *   
00020  * The above copyright notice and this permission notice shall be included in *
00021  * all copies or substantial portions of the Software.                        *   
00022  *                                                                            *   
00023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00024  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *   
00025  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *   
00026  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *   
00027  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *   
00028  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00029  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *   
00030  * -------------------------------------------------------------------------- */
00031 
00032 /* This is based on WaterDroplet.h, but instead of generating a droplet of    *
00033  * water, it generates a "droplet" of P12 ligands.  Peter recommends using    *
00034 *  a factory class -- I leave that to future generations to consider.         *
00035 */
00036 
00037 
00038 #include "molmodel/internal/common.h"
00039 #include "molmodel/internal/Compound.h"
00040 #include <iostream>
00041 #include <fstream>
00042 //#include "/Users/samuelflores/rna-dynamics/Water.h"
00043 //#include <ios>
00044 
00045 namespace SimTK 
00046 {
00047 
00048 class LigandDroplet : public Compound { public:
00049         LigandDroplet(CompoundSystem &system 
00050         , TinkerDuMMForceFieldSubsystem &dumm
00051         , GeneralForceSubsystem& forces
00052         , Vec3 dropletCenter = Vec3(0,0,0 )
00053         , float dropletRadius = 2.50  //in nm, of course
00054         , float arista = 1.6  // this is enough to separate out the ligands sufficiently     
00055         )
00056         {   
00057     Vec3 atomLocation;
00058     AtomPathName myAtomName;
00059     float shellRadius =10.0; //nanometers
00060     int cellsAcross = dropletRadius*2/arista+1; // number of cells across.  add 1 b.c. water molecules are at corners of cells.
00061     std::cout<<"cellsAcross = "<<cellsAcross<<std::endl;
00062     int totalAtoms =0;
00063     int      myWaterVecOccupation[cellsAcross][cellsAcross][cellsAcross];
00064     int numWater =0;//lsAcross*cellsAcross*cellsAcross;
00065 
00066         VanderWallSphere myVanderWallSphere( forces,  dumm,dropletCenter,shellRadius, .1            , 1.0           );
00067 
00068     float myRadius=0.;
00069         for (int xi = 0; xi < cellsAcross; xi++)
00070             for (int yi = 0; yi < cellsAcross; yi++)
00071                 for (int zi = 0; zi < cellsAcross; zi++)
00072                     {
00073                 cout<<"for indices "<<xi<<","<<yi<<","<<zi<<endl;
00074                 
00075                 cout<<" checking condition: "<<dropletCenter[0]<<","<<xi<<" , = "<<pow((dropletCenter[0]-(xi*arista-dropletRadius)),2)<<endl;
00076                 myRadius = pow((pow((xi*arista-dropletRadius),float(2))+ pow((yi*arista-dropletRadius),float(2))+ pow((zi*arista-dropletRadius),float(2))),float(.5) );
00077                 cout<<"radius = "<<myRadius<<endl;
00078                 if (myRadius <= dropletRadius) //(pow((pow((dropletCenter[0]-(xi*arista+dropletRadius)),2)+ pow((dropletCenter[1]-(yi*arista+dropletRadius)),2)+ pow((dropletCenter[2]-(zi*arista+dropletRadius)),2)),.5 ) <= dropletRadius)  
00079                     {
00080                         
00081                     numWater++;myWaterVecOccupation[xi][yi][zi] = 1;
00082                     }
00083                 else
00084                     {cout<<"outside of water droplet radius; no water to be placed here."<<endl; myWaterVecOccupation[xi][yi][zi] = 0;}       
00085             }   
00086     //Count the atoms in the CompoundSystem
00087     
00088         for (int i =0 ; i< system.getNumCompounds(); i++)
00089     {
00090         cout<<"counting atoms in compound # "<<i<<endl; 
00091         totalAtoms += system.updCompound(Compound::Index(i)).getNAtoms();
00092     }   
00093     cout<<"counted "<<totalAtoms<<" total atoms."<<endl;
00094     //Create an array to hold their locations
00095     Vec3 atomLocationArray[totalAtoms];
00096     int myAtomIndex = 0;
00097     //iState state = system.realizeTopology();
00098     for (int i =0 ; i< system.getNumCompounds(); i++)
00099     {
00100         for (int j = 0; j< system.updCompound(Compound::Index(i)).getNAtoms(); j++)
00101         {
00102             Compound & myCompound = system.updCompound(Compound::Index(i));
00103             myAtomName = myCompound.getAtomName(Compound::AtomIndex(j));
00104             atomLocationArray[myAtomIndex] = myCompound.calcDefaultAtomLocationInGroundFrame(myAtomName);
00105             //atomLocationArray[myAtomIndex] = myCompound.getDefaultAtomLocation(myAtomName);
00106             //atomLocationArray[myAtomIndex] = myCompound.getTopLevelTransform() * atomLocationArray[myAtomIndex] ;  
00107             //atomLocationArray[myAtomIndex] = system.updCompound(Compound::Index(i)).calcAtomLocationInGroundFrame(state,Compound::AtomIndex(j));
00108             cout << "myAtomName= "<<myAtomName<<" atomLocation= "<<atomLocationArray[myAtomIndex]<<endl;
00109             int myxi = (atomLocationArray[myAtomIndex][0]-dropletCenter[0]+dropletRadius)/arista+.5;
00110             int myyi = (atomLocationArray[myAtomIndex][1]-dropletCenter[1]+dropletRadius)/arista+.5;
00111             int myzi = (atomLocationArray[myAtomIndex][2]-dropletCenter[2]+dropletRadius)/arista+.5;
00112             cout<<" indices = "<<myxi<<","<<myyi<<","<<myzi<<endl;
00113             if (((myxi < cellsAcross) && (myxi >=0))
00114                 && ((myyi < cellsAcross) && (myyi >=0))
00115                 && ((myzi < cellsAcross) && (myzi >=0))
00116                 && (myWaterVecOccupation[myxi][myyi][myzi] == 1))
00117             {
00118                     numWater--;
00119                     cout<<"setting an occupation to 0"<<endl;                   
00120                     myWaterVecOccupation[myxi][myyi][myzi] = 0;         
00121             }
00122             myAtomIndex++;
00123         }
00124     }
00125 
00126     cout<<"about to create array of "<<numWater<<" water molecules."<<endl;
00127     P12   * myWaterVec[numWater];
00128         for (int k =0;k<numWater;k++)   {
00129         myWaterVec[k]=new   P12(dumm);
00130         (*myWaterVec[k]).setPdbResidueName("P12");
00131         (*myWaterVec[k]).setPdbResidueNumber(k+1  );
00132         (*myWaterVec[k]).setPdbChainId('D');
00133     }
00134 
00135     int myWaterIndex =-1;
00136         for (int xi = 0; xi < cellsAcross; xi++)
00137             for (int yi = 0; yi < cellsAcross; yi++)
00138                 for (int zi = 0; zi < cellsAcross; zi++)
00139             {
00140                 cout<<"checking occupation for "<<xi<<","<<yi<<","<<zi<<endl;
00141                 if (myWaterVecOccupation[xi][yi][zi]) 
00142                 {
00143                     myWaterIndex++;
00144                     if (myWaterIndex > numWater) {cout << "Attempted to adopt more water than exists in array"<<endl; exit(1);}
00145                     cout<<"adopting water at "<< xi*arista-dropletRadius+dropletCenter[0]<<","<<yi*arista-dropletRadius+dropletCenter[1]<<"=,"<<zi*arista-dropletRadius+dropletCenter[2]<<endl;
00146                     Rotation myRotation(45.*Deg2Rad, YAxis);
00147                     myRotation =  myRotation * Rotation(45.*Deg2Rad, XAxis);
00148                     Transform myTransform(myRotation,Vec3(xi*arista-dropletRadius+dropletCenter[0],yi*arista-dropletRadius+dropletCenter[1],zi*arista-dropletRadius+dropletCenter[2]));
00149                         system.adoptCompound(*myWaterVec[myWaterIndex],myTransform);//Vec3(xi*arista-dropletRadius+dropletCenter[0],yi*arista-dropletRadius+dropletCenter[1],zi*arista-dropletRadius+dropletCenter[2]));
00150                 }   
00151             }
00152         
00153         
00154     
00155 
00156     }
00157 };
00158 }

Generated on Fri Sep 26 07:44:13 2008 for SimTKcore by  doxygen 1.5.6