1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
// $Id: MinimizeCLI.cpp 1345 2010-02-28 12:59:31Z glandrum $
//
// Copyright (C) 2004 Rational Discovery LLC
// All Rights Reserved
//
#include <iostream>
#include <RDGeneral/Invariant.h>
#include <RDGeneral/utils.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/FileParsers/FileParsers.h>
#include <GraphMol/FileParsers/MolSupplier.h>
#include <GraphMol/ForceFieldHelpers/UFF/AtomTyper.h>
#include <GraphMol/ForceFieldHelpers/UFF/Builder.h>
#include <ForceField/ForceField.h>
using namespace RDKit;
void runMol(ROMol *mol,int checkEvery=10,bool verbose=true){
ForceFields::ForceField *field;
std::cout << MolToMolBlock(*mol) << "$$$$" << std::endl;
try{
field=UFF::constructForceField(*mol,2.5);
} catch (...) {
field=0;
}
if(field){
field->initialize();
int needMore=1;
int nPasses=0;
while(needMore){
#if 1
needMore = field->minimize(checkEvery);
if(verbose) std::cerr << "\t" << ++nPasses << std::endl;
#else
needMore = field->minimize(1);
std::cout << MolToMolBlock(mol) << "$$$$" << std::endl;
#endif
}
std::cout << MolToMolBlock(*mol) << "$$$$" << std::endl;
delete field;
} else {
std::cerr << "failed";
}
}
void runMolFile(std::string fileName,int checkEvery=10){
RWMol *mol=MolFileToMol(fileName,false);
TEST_ASSERT(mol);
MolOps::sanitizeMol(*mol);
ROMol *mol2=MolOps::addHs(*mol,false,true);
runMol(mol2,checkEvery);
delete mol;
delete mol2;
}
void runSDFile(std::string fileName,int checkEvery=10){
SDMolSupplier suppl(fileName,false);
RWMol *mol;
mol = (RWMol *)suppl.next();
while(mol){
std::string name;
mol->getProp("_Name",name);
std::cerr << "Mol: " << name << std::endl;
try{
MolOps::sanitizeMol(*mol);
} catch (...) {
std::cerr << " sanitization failed" << std::endl;
delete mol;
mol = 0;
}
if(mol){
ROMol *mol2=MolOps::addHs(*mol,false,true);
delete mol;
runMol(mol2,checkEvery,false);
delete mol2;
}
mol = (RWMol *)suppl.next();
}
}
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
int main(int argc,char *argv[]){
PRECONDITION(argc>1,"bad arguments");
std::string fileName=argv[1];
int checkEvery=10;
std::cerr << ">" << fileName<< " " << fileName.find(".sdf") << std::endl;
if(fileName.find(".sdf")==std::string::npos){
runMolFile(fileName,checkEvery);
} else {
runSDFile(fileName,checkEvery);
}
std::cerr << "done" << std::endl;
}
|