| 1 | 
gezelter | 
1295 | 
#include <iostream> | 
| 2 | 
  | 
  | 
#include <fstream> | 
| 3 | 
  | 
  | 
#include <string> | 
| 4 | 
  | 
  | 
#include <vector> | 
| 5 | 
  | 
  | 
#include "shaperCmd.h" | 
| 6 | 
  | 
  | 
#include "PDBReader.hpp" | 
| 7 | 
  | 
  | 
#include "RigidBody.hpp" | 
| 8 | 
  | 
  | 
#include "GridBuilder.hpp" | 
| 9 | 
  | 
  | 
#include "SphereHarm.hpp" | 
| 10 | 
  | 
  | 
 | 
| 11 | 
  | 
  | 
#define MK_STR(s) # s | 
| 12 | 
  | 
  | 
#define STR_DEFINE(t, s) t = MK_STR(s) | 
| 13 | 
  | 
  | 
#define CHARMM 1 | 
| 14 | 
  | 
  | 
#define AMBER  2 | 
| 15 | 
  | 
  | 
#define LJ     3 | 
| 16 | 
  | 
  | 
#define GAFF   4 | 
| 17 | 
  | 
  | 
#define OPLS   5 | 
| 18 | 
  | 
  | 
 | 
| 19 | 
  | 
  | 
int count_tokens(char *line, char *delimiters); | 
| 20 | 
  | 
  | 
using namespace std; | 
| 21 | 
  | 
  | 
 | 
| 22 | 
  | 
  | 
class Atype{ | 
| 23 | 
  | 
  | 
public: | 
| 24 | 
  | 
  | 
  Atype() { | 
| 25 | 
  | 
  | 
    mass = 0.0; | 
| 26 | 
  | 
  | 
    rpar = 0.0; | 
| 27 | 
  | 
  | 
    eps = 0.0; | 
| 28 | 
  | 
  | 
  } | 
| 29 | 
  | 
  | 
 | 
| 30 | 
  | 
  | 
  void setMass(double m) {mass = m;} | 
| 31 | 
  | 
  | 
  void setRpar(double rp) {rpar = rp;} | 
| 32 | 
  | 
  | 
  void setEps(double e) {eps = e;} | 
| 33 | 
  | 
  | 
  void setType(char* t) {strcpy(type, t);} | 
| 34 | 
  | 
  | 
  double getMass() {return mass;} | 
| 35 | 
  | 
  | 
  double getRpar() {return rpar;} | 
| 36 | 
  | 
  | 
  double getEps() {return eps;} | 
| 37 | 
  | 
  | 
  char *getType() {return type;} | 
| 38 | 
  | 
  | 
   | 
| 39 | 
  | 
  | 
private: | 
| 40 | 
  | 
  | 
  char type[100]; | 
| 41 | 
  | 
  | 
  double mass; | 
| 42 | 
  | 
  | 
  double rpar; | 
| 43 | 
  | 
  | 
  double eps; | 
| 44 | 
  | 
  | 
}; | 
| 45 | 
  | 
  | 
   | 
| 46 | 
  | 
  | 
int main(int argc, char* argv[]){ | 
| 47 | 
  | 
  | 
 | 
| 48 | 
  | 
  | 
  gengetopt_args_info args_info; | 
| 49 | 
  | 
  | 
 | 
| 50 | 
  | 
  | 
  vector<Atype*>   vdwAtypes; | 
| 51 | 
  | 
  | 
  vector<Atype*>::iterator i; | 
| 52 | 
  | 
  | 
  Atype* at; | 
| 53 | 
  | 
  | 
  RigidBody* rb; | 
| 54 | 
  | 
  | 
  vector<VDWAtom*> theAtoms; | 
| 55 | 
  | 
  | 
  vector<VDWAtom*>::iterator j; | 
| 56 | 
  | 
  | 
  VDWAtom* atom; | 
| 57 | 
  | 
  | 
  GridBuilder* gb; | 
| 58 | 
  | 
  | 
  vector<double> sigmaGrid; | 
| 59 | 
  | 
  | 
  vector<double> epsGrid; | 
| 60 | 
  | 
  | 
  vector<double> sGrid; | 
| 61 | 
  | 
  | 
  SphereHarm* harmonize; | 
| 62 | 
  | 
  | 
   | 
| 63 | 
  | 
  | 
  double mass, rpar, eps; | 
| 64 | 
  | 
  | 
  double xyz3[3]; | 
| 65 | 
  | 
  | 
  double moments[3][3]; | 
| 66 | 
chrisfen | 
1312 | 
  double tolerance; | 
| 67 | 
gezelter | 
1295 | 
  string fileName;   | 
| 68 | 
  | 
  | 
  char vdwFileName[2002]; | 
| 69 | 
  | 
  | 
  char structureFileName[2002]; | 
| 70 | 
  | 
  | 
  char temp[200]; | 
| 71 | 
  | 
  | 
  char readLine[500]; | 
| 72 | 
  | 
  | 
  char xyzFile[200]; | 
| 73 | 
  | 
  | 
  char shapeFile[200]; | 
| 74 | 
  | 
  | 
  char shapeName[80]; | 
| 75 | 
  | 
  | 
  FILE *vdwFile, *structureFile; | 
| 76 | 
  | 
  | 
  char* ffPath_env = "VDW_PATH"; | 
| 77 | 
  | 
  | 
  char* ffPath; | 
| 78 | 
  | 
  | 
  char* eof_test; | 
| 79 | 
  | 
  | 
  char* foo; | 
| 80 | 
  | 
  | 
  char* myType; | 
| 81 | 
  | 
  | 
  char* vType; | 
| 82 | 
  | 
  | 
  char *token; | 
| 83 | 
  | 
  | 
  const char *file; | 
| 84 | 
  | 
  | 
  const char *period = "."; | 
| 85 | 
  | 
  | 
  int k; | 
| 86 | 
  | 
  | 
  int lineNum; | 
| 87 | 
  | 
  | 
  int nTokens; | 
| 88 | 
  | 
  | 
  int FF; | 
| 89 | 
  | 
  | 
  int bandwidth; | 
| 90 | 
  | 
  | 
  int gridwidth; | 
| 91 | 
  | 
  | 
  short int gotMatch; | 
| 92 | 
  | 
  | 
 | 
| 93 | 
  | 
  | 
  //parse the command line options | 
| 94 | 
  | 
  | 
  if (cmdline_parser (argc, argv, &args_info) != 0) | 
| 95 | 
  | 
  | 
    exit(1) ; | 
| 96 | 
  | 
  | 
 | 
| 97 | 
  | 
  | 
  if (args_info.input_given){ | 
| 98 | 
  | 
  | 
    fileName = args_info.input_arg; | 
| 99 | 
  | 
  | 
  } | 
| 100 | 
  | 
  | 
  else{ | 
| 101 | 
  | 
  | 
    std::cerr << "Does not have input file name" << endl; | 
| 102 | 
  | 
  | 
    exit(1); | 
| 103 | 
  | 
  | 
  } | 
| 104 | 
  | 
  | 
 | 
| 105 | 
  | 
  | 
  file = fileName.c_str(); | 
| 106 | 
  | 
  | 
  strcpy(xyzFile, file); | 
| 107 | 
  | 
  | 
  token = strtok(xyzFile, period); | 
| 108 | 
  | 
  | 
  strcpy(xyzFile, token); | 
| 109 | 
  | 
  | 
  strcpy(shapeFile, token); | 
| 110 | 
  | 
  | 
  strcpy(shapeName, token); | 
| 111 | 
  | 
  | 
  strcat(xyzFile, "Ref.xyz"); | 
| 112 | 
  | 
  | 
  strcat(shapeFile, ".shape"); | 
| 113 | 
  | 
  | 
  strcat(shapeName, "_RB_0"); | 
| 114 | 
  | 
  | 
  ofstream xfiles(xyzFile); | 
| 115 | 
  | 
  | 
   | 
| 116 | 
  | 
  | 
  //the bandwidth has a default value (default=16), so it is always given | 
| 117 | 
  | 
  | 
  bandwidth = args_info.bandwidth_arg; | 
| 118 | 
  | 
  | 
  gridwidth = bandwidth*2; | 
| 119 | 
chrisfen | 
1312 | 
  | 
| 120 | 
  | 
  | 
  //the tolerance has a default value (default=0.01), so it is always given | 
| 121 | 
  | 
  | 
  tolerance = args_info.tolerance_arg; | 
| 122 | 
  | 
  | 
 | 
| 123 | 
gezelter | 
1295 | 
  if (args_info.charmm_given) { | 
| 124 | 
  | 
  | 
    FF=CHARMM; | 
| 125 | 
  | 
  | 
    strcpy(vdwFileName, "charmm27.vdw"); | 
| 126 | 
  | 
  | 
  } | 
| 127 | 
  | 
  | 
 | 
| 128 | 
  | 
  | 
  if (args_info.amber_given) { | 
| 129 | 
  | 
  | 
    FF=AMBER; | 
| 130 | 
  | 
  | 
    strcpy(vdwFileName, "amber99.vdw"); | 
| 131 | 
  | 
  | 
  } | 
| 132 | 
  | 
  | 
 | 
| 133 | 
  | 
  | 
  if (args_info.lj_given) { | 
| 134 | 
  | 
  | 
    FF=LJ; | 
| 135 | 
  | 
  | 
    strcpy(vdwFileName, "LJ.vdw"); | 
| 136 | 
  | 
  | 
  } | 
| 137 | 
  | 
  | 
 | 
| 138 | 
  | 
  | 
  if (args_info.gaff_given) { | 
| 139 | 
  | 
  | 
    FF=GAFF; | 
| 140 | 
  | 
  | 
    strcpy(vdwFileName, "gaff.vdw"); | 
| 141 | 
  | 
  | 
  } | 
| 142 | 
  | 
  | 
   | 
| 143 | 
  | 
  | 
  if (args_info.opls_given) { | 
| 144 | 
  | 
  | 
    FF=OPLS; | 
| 145 | 
  | 
  | 
    strcpy(vdwFileName, "oplsaal.vdw"); | 
| 146 | 
  | 
  | 
  } | 
| 147 | 
  | 
  | 
 | 
| 148 | 
  | 
  | 
 | 
| 149 | 
  | 
  | 
  printf ("opening %s\n", vdwFileName); | 
| 150 | 
  | 
  | 
  vdwFile = fopen( vdwFileName, "r" ); | 
| 151 | 
  | 
  | 
   | 
| 152 | 
  | 
  | 
  if( vdwFile == NULL ){ | 
| 153 | 
  | 
  | 
        | 
| 154 | 
  | 
  | 
    // next see if the force path enviorment variable is set | 
| 155 | 
  | 
  | 
     | 
| 156 | 
  | 
  | 
    ffPath = getenv( ffPath_env ); | 
| 157 | 
  | 
  | 
    if( ffPath == NULL ) { | 
| 158 | 
  | 
  | 
      STR_DEFINE(ffPath, FRC_PATH ); | 
| 159 | 
  | 
  | 
    } | 
| 160 | 
  | 
  | 
     | 
| 161 | 
  | 
  | 
    strcpy( temp, ffPath ); | 
| 162 | 
  | 
  | 
    strcat( temp, "/" ); | 
| 163 | 
  | 
  | 
    strcat( temp, vdwFileName ); | 
| 164 | 
  | 
  | 
    strcpy( vdwFileName, temp ); | 
| 165 | 
  | 
  | 
     | 
| 166 | 
  | 
  | 
    printf ("opening %s\n", vdwFileName); | 
| 167 | 
  | 
  | 
    vdwFile = fopen( vdwFileName, "r" ); | 
| 168 | 
  | 
  | 
     | 
| 169 | 
  | 
  | 
    if( vdwFile == NULL ){ | 
| 170 | 
  | 
  | 
       | 
| 171 | 
  | 
  | 
      printf(  "Error opening the vanDerWaals parameter file: %s\n" | 
| 172 | 
  | 
  | 
               "Have you tried setting the VDW_PARAM_DIR environment " | 
| 173 | 
  | 
  | 
               "variable?\n", | 
| 174 | 
  | 
  | 
               vdwFileName ); | 
| 175 | 
  | 
  | 
      exit(-1); | 
| 176 | 
  | 
  | 
    } | 
| 177 | 
  | 
  | 
  } | 
| 178 | 
  | 
  | 
  printf( "VDW file %s opened sucessfully.\n", vdwFileName ); | 
| 179 | 
  | 
  | 
  lineNum = 0; | 
| 180 | 
  | 
  | 
   | 
| 181 | 
  | 
  | 
  eof_test = fgets( readLine, sizeof(readLine), vdwFile ); | 
| 182 | 
  | 
  | 
  lineNum++; | 
| 183 | 
  | 
  | 
   | 
| 184 | 
  | 
  | 
  if( eof_test == NULL ){ | 
| 185 | 
  | 
  | 
    printf("Error in reading Atoms from force file at line %d.\n", | 
| 186 | 
  | 
  | 
           lineNum ); | 
| 187 | 
  | 
  | 
    exit(-1); | 
| 188 | 
  | 
  | 
  } | 
| 189 | 
  | 
  | 
   | 
| 190 | 
  | 
  | 
  while( eof_test != NULL ){ | 
| 191 | 
  | 
  | 
    // toss comment lines | 
| 192 | 
  | 
  | 
    if( readLine[0] != '!' && readLine[0] != '#' ){ | 
| 193 | 
  | 
  | 
       | 
| 194 | 
  | 
  | 
      nTokens = count_tokens(readLine, " ,;\t"); | 
| 195 | 
  | 
  | 
      if (nTokens < 4) { | 
| 196 | 
  | 
  | 
        printf("Not enough tokens on line %d.\n", lineNum); | 
| 197 | 
  | 
  | 
        exit(-1); | 
| 198 | 
  | 
  | 
      }  | 
| 199 | 
  | 
  | 
       | 
| 200 | 
  | 
  | 
      at = new Atype(); | 
| 201 | 
  | 
  | 
      foo = strtok(readLine, " ,;\t"); | 
| 202 | 
  | 
  | 
      at->setType(foo); | 
| 203 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t");        | 
| 204 | 
  | 
  | 
      mass = atof(foo); | 
| 205 | 
  | 
  | 
      at->setMass(mass); | 
| 206 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t"); | 
| 207 | 
  | 
  | 
      rpar = atof(foo); | 
| 208 | 
  | 
  | 
      at->setRpar(rpar); | 
| 209 | 
  | 
  | 
      foo = strtok(NULL, " ,;\t"); | 
| 210 | 
  | 
  | 
      eps = atof(foo);   | 
| 211 | 
  | 
  | 
      at->setEps(eps); | 
| 212 | 
  | 
  | 
      vdwAtypes.push_back(at);         | 
| 213 | 
  | 
  | 
    } | 
| 214 | 
  | 
  | 
    eof_test = fgets( readLine, sizeof(readLine), vdwFile ); | 
| 215 | 
  | 
  | 
    lineNum++; | 
| 216 | 
  | 
  | 
  }           | 
| 217 | 
  | 
  | 
   | 
| 218 | 
  | 
  | 
  fclose( vdwFile ); | 
| 219 | 
  | 
  | 
   | 
| 220 | 
  | 
  | 
  printf("%d Atom Types read from VDW file\n", vdwAtypes.size()); | 
| 221 | 
  | 
  | 
 | 
| 222 | 
  | 
  | 
  // Now, open and parse the input file! | 
| 223 | 
  | 
  | 
 | 
| 224 | 
  | 
  | 
  strcpy(structureFileName, fileName.c_str() ); | 
| 225 | 
  | 
  | 
 | 
| 226 | 
  | 
  | 
  PDBReader* PDBread = new PDBReader(); | 
| 227 | 
  | 
  | 
  PDBread->setPDBfile(structureFileName); | 
| 228 | 
  | 
  | 
  theAtoms = PDBread->getAtomList(); | 
| 229 | 
  | 
  | 
  printf("Found %d atoms\n", theAtoms.size()); | 
| 230 | 
  | 
  | 
 | 
| 231 | 
  | 
  | 
  for( j = theAtoms.begin(); j !=  theAtoms.end(); ++j){ | 
| 232 | 
  | 
  | 
    atom = *j; | 
| 233 | 
  | 
  | 
    myType = atom->getType(); | 
| 234 | 
  | 
  | 
    gotMatch = 0; | 
| 235 | 
  | 
  | 
 | 
| 236 | 
  | 
  | 
    for( i = vdwAtypes.begin(); i !=  vdwAtypes.end(); ++i){ | 
| 237 | 
  | 
  | 
      at = *i; | 
| 238 | 
  | 
  | 
      vType = at->getType(); | 
| 239 | 
  | 
  | 
       | 
| 240 | 
  | 
  | 
      if (!strcasecmp(myType, vType)) { | 
| 241 | 
  | 
  | 
        atom->setMass(at->getMass()); | 
| 242 | 
  | 
  | 
        atom->setRpar(at->getRpar()); | 
| 243 | 
  | 
  | 
        atom->setEps(at->getEps()); | 
| 244 | 
  | 
  | 
        gotMatch = 1;         | 
| 245 | 
  | 
  | 
      } | 
| 246 | 
  | 
  | 
    } | 
| 247 | 
  | 
  | 
    if (!gotMatch) {       | 
| 248 | 
  | 
  | 
      printf("No matches found for %s, ", myType); | 
| 249 | 
  | 
  | 
      myType = atom->getBase(); | 
| 250 | 
  | 
  | 
      printf("trying with BaseType %s\n", myType); | 
| 251 | 
  | 
  | 
      for( i = vdwAtypes.begin(); i !=  vdwAtypes.end(); ++i){ | 
| 252 | 
  | 
  | 
        at = *i; | 
| 253 | 
  | 
  | 
        vType = at->getType();         | 
| 254 | 
  | 
  | 
        if (!strcasecmp(myType, vType)) { | 
| 255 | 
  | 
  | 
          atom->setMass(at->getMass()); | 
| 256 | 
  | 
  | 
          atom->setRpar(at->getRpar()); | 
| 257 | 
  | 
  | 
          atom->setEps(at->getEps()); | 
| 258 | 
  | 
  | 
          gotMatch = 1; | 
| 259 | 
  | 
  | 
        } | 
| 260 | 
  | 
  | 
      } | 
| 261 | 
  | 
  | 
    } | 
| 262 | 
  | 
  | 
 | 
| 263 | 
  | 
  | 
    if (!gotMatch) { | 
| 264 | 
  | 
  | 
      printf("No matches found with BaseType!\n"); | 
| 265 | 
  | 
  | 
    } | 
| 266 | 
  | 
  | 
  } | 
| 267 | 
  | 
  | 
 | 
| 268 | 
  | 
  | 
  rb = new RigidBody(); | 
| 269 | 
  | 
  | 
  for( j = theAtoms.begin(); j !=  theAtoms.end(); ++j){ | 
| 270 | 
  | 
  | 
    rb->addAtom(*j); | 
| 271 | 
  | 
  | 
  } | 
| 272 | 
  | 
  | 
 | 
| 273 | 
  | 
  | 
  rb->calcRefCoords(); | 
| 274 | 
  | 
  | 
   | 
| 275 | 
  | 
  | 
  //print a reference coordinate xyz file | 
| 276 | 
  | 
  | 
  xfiles << rb->getNumAtoms() << "\n\n"; | 
| 277 | 
  | 
  | 
  for (k=0; k<rb->getNumAtoms(); k++){ | 
| 278 | 
  | 
  | 
    rb->getAtomRefCoor(xyz3, k); | 
| 279 | 
  | 
  | 
    xfiles << rb->getAtomBase(k) << "\t" << | 
| 280 | 
  | 
  | 
              xyz3[0] << "\t" << xyz3[1] << "\t" << | 
| 281 | 
  | 
  | 
              xyz3[2] << "\n"; | 
| 282 | 
  | 
  | 
  } | 
| 283 | 
  | 
  | 
   | 
| 284 | 
  | 
  | 
  gb = new GridBuilder(rb, gridwidth); | 
| 285 | 
  | 
  | 
 | 
| 286 | 
  | 
  | 
  cout << "Doing GridBuilder calculations...\n"; | 
| 287 | 
  | 
  | 
  gb->launchProbe(FF, sigmaGrid, sGrid, epsGrid); | 
| 288 | 
  | 
  | 
   | 
| 289 | 
  | 
  | 
  gb->printGridFiles(); | 
| 290 | 
  | 
  | 
   | 
| 291 | 
  | 
  | 
  //load the grid element values to the main grid vectors | 
| 292 | 
  | 
  | 
  for (k=0; k<gridwidth*gridwidth; k++){ | 
| 293 | 
  | 
  | 
    sigmaGrid.push_back(gb->passSig(k)); | 
| 294 | 
  | 
  | 
    sGrid.push_back(gb->passS(k)); | 
| 295 | 
  | 
  | 
    epsGrid.push_back(gb->passEps(k)); | 
| 296 | 
  | 
  | 
  } | 
| 297 | 
  | 
  | 
 | 
| 298 | 
  | 
  | 
  //build the spherical harmonic transform object | 
| 299 | 
  | 
  | 
  harmonize = new SphereHarm( bandwidth ); | 
| 300 | 
  | 
  | 
  rb->getI(moments); | 
| 301 | 
  | 
  | 
  harmonize->printShapesFileStart(shapeFile, shapeName, rb->getMass(), | 
| 302 | 
  | 
  | 
                                  moments); | 
| 303 | 
  | 
  | 
   | 
| 304 | 
  | 
  | 
  printf("Doing SHAPE calculations and outputting results...\n"); | 
| 305 | 
  | 
  | 
  //do the transforms and write to the shapes file | 
| 306 | 
  | 
  | 
  harmonize->doTransforms(sigmaGrid); | 
| 307 | 
  | 
  | 
  harmonize->printToShapesFile(shapeFile, 0); | 
| 308 | 
  | 
  | 
  harmonize->doTransforms(sGrid); | 
| 309 | 
  | 
  | 
  harmonize->printToShapesFile(shapeFile, 1); | 
| 310 | 
  | 
  | 
  harmonize->doTransforms(epsGrid); | 
| 311 | 
  | 
  | 
  harmonize->printToShapesFile(shapeFile, 2); | 
| 312 | 
  | 
  | 
   | 
| 313 | 
  | 
  | 
  //clean everything up | 
| 314 | 
  | 
  | 
  harmonize->~SphereHarm();   | 
| 315 | 
  | 
  | 
  printf("Thank you for using SHAPES.  Enjoy your potential!\n"); | 
| 316 | 
  | 
  | 
} | 
| 317 | 
  | 
  | 
 | 
| 318 | 
  | 
  | 
int count_tokens(char *line, char *delimiters) { | 
| 319 | 
  | 
  | 
/* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */ | 
| 320 | 
  | 
  | 
  | 
| 321 | 
  | 
  | 
  char *working_line;   /* WORKING COPY OF LINE. */ | 
| 322 | 
  | 
  | 
  int ntokens;          /* NUMBER OF TOKENS FOUND IN LINE. */ | 
| 323 | 
  | 
  | 
  char *strtok_ptr;     /* POINTER FOR STRTOK. */ | 
| 324 | 
  | 
  | 
    | 
| 325 | 
  | 
  | 
  strtok_ptr= working_line= strdup(line); | 
| 326 | 
  | 
  | 
    | 
| 327 | 
  | 
  | 
  ntokens=0; | 
| 328 | 
  | 
  | 
  while (strtok(strtok_ptr,delimiters)!=NULL) | 
| 329 | 
  | 
  | 
    { | 
| 330 | 
  | 
  | 
      ntokens++; | 
| 331 | 
  | 
  | 
      strtok_ptr=NULL; | 
| 332 | 
  | 
  | 
    } | 
| 333 | 
  | 
  | 
    | 
| 334 | 
  | 
  | 
  free(working_line); | 
| 335 | 
  | 
  | 
  return(ntokens); | 
| 336 | 
  | 
  | 
} |