int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
    return 1;
  }

  // Read the file
  shared_ptr<OBMol> mol = GetMol(argv[1]);

  // Create the OBConformerSearch object
  OBConformerSearch cs;
  
  // Setup 
  std::cout << "Setting up conformer searching..." << std::endl
            << "   conformers:  30" << std::endl
            << "   children:    5" << std::endl
            << "   mutability:  5" << std::endl
            << "   convergence: 25" << std::endl;
  cs.Setup(*mol.get(),
           30, // numConformers
           5, // numChildren
           5, // mutability
           25); // convergence

  // Perform searching
  cs.Search();

  // Print the rotor keys
  RotorKeys keys = cs.GetRotorKeys();
  for (RotorKeys::iterator key = keys.begin(); key != keys.end(); ++key) {
    for (unsigned int i = 1; i < key->size(); ++i)
      std::cout << key->at(i) << " ";
    std::cout << std::endl;
  }

  // Get the conformers
  cs.GetConformers(*mol.get());

  std::cout << mol->NumConformers() << std::endl;
  OBConversion conv;
  conv.SetOutFormat("sdf");
  for (unsigned int c = 0; c < mol->NumConformers(); ++c) {
    mol->SetConformer(c);
    conv.Write(mol.get(), &std::cerr);
  }

}
Пример #2
0
  bool OpConformer::Do(OBBase* pOb, const char* OptionText, OpMap* pmap, OBConversion*)
  {
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
    if(!pmol)
      return false;
    pmol->AddHydrogens(false, false);

    OpMap::const_iterator iter;
    bool log = false;
    bool systematic = false;
    bool random = false;
    bool weighted = false;
    int numConformers = 30;

    iter = pmap->find("log");
    if(iter!=pmap->end())
      log=true;

    iter = pmap->find("nconf");
    if(iter!=pmap->end())
      getInteger(iter->second, numConformers);

    iter = pmap->find("systematic");
    if(iter!=pmap->end())
      systematic = true;

    iter = pmap->find("random");
    if(iter!=pmap->end())
      random = true;

    iter = pmap->find("weighted");
    if(iter!=pmap->end())
      weighted = true;

    if (systematic || random || weighted) {
      std::string ff = "MMFF94";
      iter = pmap->find("ff");
      if(iter!=pmap->end())
        ff = iter->second;
      OBForceField* pFF = OBForceField::FindForceField(ff);

      // set some force field variables
      pFF->SetLogFile(&clog);
      pFF->SetLogLevel(log ? OBFF_LOGLVL_MEDIUM : OBFF_LOGLVL_NONE);

      if (!pFF->Setup(*pmol)) {
        cerr  << "Could not setup force field." << endl;
        return false;
      }
    } else {
      int numChildren = 5;
      int mutability = 5;
      int convergence = 25;
      std::string score = "rmsd";

      iter = pmap->find("children");
      if(iter!=pmap->end())
        getInteger(iter->second, numChildren);

      iter = pmap->find("mutability");
      if(iter!=pmap->end())
        getInteger(iter->second, mutability);

      iter = pmap->find("convergence");
      if(iter!=pmap->end())
        getInteger(iter->second, convergence);

      iter = pmap->find("score");
      if(iter!=pmap->end())
        score = iter->second;

      OBConformerSearch cs;
      if (score == "energy")
        cs.SetScore(new OBEnergyConformerScore);

      if (cs.Setup(*pmol, numConformers, numChildren, mutability, convergence)) {
        cs.Search();
        cs.GetConformers(*pmol);
      }
    }

    return true;
  }
Пример #3
0
  bool OpConformer::Do(OBBase* pOb, const char* OptionText, OpMap* pmap, OBConversion*)
  {
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
    if(!pmol)
      return false;
    pmol->AddHydrogens(false, false);

    OpMap::const_iterator iter;
    bool log = false;
    bool systematic = false;
    bool random = false;
    bool weighted = false;
    bool fast = false;
    int numConformers = 30;

    iter = pmap->find("log");
    if(iter!=pmap->end())
      log=true;

    iter = pmap->find("nconf");
    if(iter!=pmap->end())
      getInteger(iter->second, numConformers);

    iter = pmap->find("systematic");
    if(iter!=pmap->end())
      systematic = true;

    iter = pmap->find("random");
    if(iter!=pmap->end())
      random = true;

    iter = pmap->find("fast");
    if(iter!=pmap->end())
      fast = true;

    iter = pmap->find("weighted");
    if(iter!=pmap->end())
      weighted = true;

    if (systematic || random || fast || weighted) {
      std::string ff = "MMFF94";
      iter = pmap->find("ff");
      if(iter!=pmap->end())
        ff = iter->second;
      OBForceField* pFF = OBForceField::FindForceField(ff);

      // set some force field variables
      pFF->SetLogFile(&clog);
      pFF->SetLogLevel(log ? OBFF_LOGLVL_MEDIUM : OBFF_LOGLVL_NONE);

      // Add cut-offs for faster conformer searching
      // Generally people will perform further optimization on a final conformer
      pFF->EnableCutOff(true);
      pFF->SetVDWCutOff(10.0);
      pFF->SetElectrostaticCutOff(20.0);
      pFF->SetUpdateFrequency(10); // delay updates of non-bonded distances

      if (!pFF->Setup(*pmol)) {
        cerr  << "Could not setup force field." << endl;
        return false;
      }

      // Perform search
      if (systematic) {
        pFF->SystematicRotorSearch(10); // 10 steepest-descent forcfield steps per conformer
      } else if (fast) {
        pFF->FastRotorSearch(true); // permute rotors
      } else if (random) {
        pFF->RandomRotorSearch(numConformers, 10);
      } else if (weighted) {
        pFF->WeightedRotorSearch(numConformers, 10);
      }
      pFF->GetConformers(*pmol);

    } else { // GA-based searching
      int numChildren = 5;
      int mutability = 5;
      int convergence = 5;
      std::string score = "rmsd";

      iter = pmap->find("children");
      if(iter!=pmap->end())
        getInteger(iter->second, numChildren);

      iter = pmap->find("mutability");
      if(iter!=pmap->end())
        getInteger(iter->second, mutability);

      iter = pmap->find("convergence");
      if(iter!=pmap->end())
        getInteger(iter->second, convergence);

      iter = pmap->find("score");
      if(iter!=pmap->end())
        score = iter->second;

      OBConformerSearch cs;
      if (score == "energy")
        cs.SetScore(new OBEnergyConformerScore);
      else if (score == "mine" || score == "minenergy")
        cs.SetScore(new OBMinimizingEnergyConformerScore);
      else if (score == "minr" || score == "minrmsd")
        cs.SetScore(new OBMinimizingRMSDConformerScore);

      if (cs.Setup(*pmol, numConformers, numChildren, mutability, convergence)) {
        cs.Search();
        cs.GetConformers(*pmol);
      }
    }

    return true;
  }