Beispiel #1
0
// Test the eigenvalue finder. Set up a diagonal matrix and conjugate
// by a rotation. That way we obtain a symmetric matrix that can be
// diagonalized. Check if the eigenvalue finder reveals the original
// diagonal elements.
void testEigenvalues()
{
  matrix3x3 Diagonal;
  for(int i=0; i<3; i++)
    for(int j=0; j<3; j++)
      Diagonal.Set(i, j, 0.0);
  Diagonal.Set(0, 0, randomizer.NextFloat());
  Diagonal.Set(1, 1, Diagonal.Get(0,0)+fabs(randomizer.NextFloat()));
  Diagonal.Set(2, 2, Diagonal.Get(1,1)+fabs(randomizer.NextFloat()));

  // test the isDiagonal() method
  VERIFY( Diagonal.isDiagonal() );

  matrix3x3 rndRotation;
  rndRotation.randomRotation(randomizer);

  // check that rndRotation is really a rotation, i.e. that randomRotation() works
  VERIFY( rndRotation.isOrthogonal() );
  
  matrix3x3 toDiagonalize = rndRotation * Diagonal * rndRotation.inverse();
  VERIFY( toDiagonalize.isSymmetric() );
  
  vector3 eigenvals;
  toDiagonalize.findEigenvectorsIfSymmetric(eigenvals);
  
  for(unsigned int j=0; j<3; j++)
    VERIFY( IsNegligible( eigenvals[j] - Diagonal.Get(j,j), Diagonal.Get(2,2) ) );
  
  VERIFY( eigenvals[0] < eigenvals[1] &&  eigenvals[1] < eigenvals[2] );
}
bool OBConformerSearch::Setup(const OBMol &mol, int numConformers, int numChildren, int mutability, int convergence)
{
    // copy some variables
    m_mol = mol;
    m_numConformers = numConformers;
    m_numChildren = numChildren;
    m_mutability = mutability;
    m_convergence = convergence;

    if (m_mol.GetCoordinates() == NULL)
        return false;

    // Initialize the OBRotorList
    m_rotorList.SetFixedBonds(m_fixedBonds);
    m_rotorList.Setup(m_mol);
    if (!m_rotorList.Size()) { // only one conformer
        return false;
    }

    // create initial population
    OBRandom generator;
    generator.TimeSeed();

    RotorKey rotorKey(m_rotorList.Size() + 1, 0); // indexed from 1
    if (IsGood(rotorKey))
        m_rotorKeys.push_back(rotorKey);
    else {
        cout << "Initial conformer does not pass filter!" << endl;
    }

    int tries = 0;
    while (m_rotorKeys.size() < m_numConformers && tries < numConformers * 1000) {
        tries++;
        // perform random mutation(s)
        OBRotorIterator ri;
        OBRotor *rotor = m_rotorList.BeginRotor(ri);
        for (int i = 1; i < m_rotorList.Size() + 1; ++i, rotor = m_rotorList.NextRotor(ri)) {
            if (generator.NextInt() % m_mutability == 0)
                rotorKey[i] = generator.NextInt() % rotor->GetResolution().size();
        }
        // duplicates are always rejected
        if (!IsUniqueKey(m_rotorKeys, rotorKey))
            continue;
        // execute filter(s)
        if (!IsGood(rotorKey))
            continue;
        // add the key
        m_rotorKeys.push_back(rotorKey);
    }

    // print out initial conformers
    cout << "Initial conformer count: " << m_rotorKeys.size() << endl;
    for (unsigned int i = 0; i < m_rotorKeys.size(); ++i) {
        for (unsigned int j = 1; j < m_rotorKeys[i].size(); ++j)
            std::cout << m_rotorKeys[i][j] << " ";
        std::cout << std::endl;
    }

    return true;
}
Beispiel #3
0
  /*! The axis of the rotation will be uniformly distributed on
    the unit sphere and the angle will be uniformly distributed in
    the interval 0..360 degrees. */
  void matrix3x3::randomRotation(OBRandom &rnd)
  {
    double rotAngle;
    vector3 v1;

    v1.randomUnitVector(&rnd);
    rotAngle = 360.0 * rnd.NextFloat();
    this->RotAboutAxisByAngle(v1,rotAngle);
  }
void OBConformerSearch::NextGeneration()
{
    // create next generation population
    OBRandom generator;
    generator.TimeSeed();

    // generate the children
    int numConformers = m_rotorKeys.size();
    for (int c = 0; c < numConformers; ++c) {
        for (int child = 0; child < m_numChildren; ++child) {
            bool foundKey = false;
            int tries = 0;
            while (!foundKey) {
                tries++;
                if (tries > 1000)
                    foundKey = true;
                RotorKey rotorKey = m_rotorKeys[c]; // copy parent gene
                // perform random mutation(s)
                OBRotorIterator ri;
                OBRotor *rotor = m_rotorList.BeginRotor(ri);
                for (int i = 1; i < m_rotorList.Size() + 1; ++i, rotor = m_rotorList.NextRotor(ri)) {
                    if (generator.NextInt() % m_mutability == 0)
                        rotorKey[i] = generator.NextInt() % rotor->GetResolution().size(); // permutate gene
                }
                // duplicates are always rejected
                if (!IsUniqueKey(m_rotorKeys, rotorKey))
                    continue;
                // execute the filter(s)
                if (!IsGood(rotorKey))
                    continue;
                // add the key
                m_rotorKeys.push_back(rotorKey); // append child to population
                // set foundKey to generate the next child
                foundKey = true;
            }
        }
    }
}
Beispiel #5
0
int math(int argc, char* argv[])
{
  int defaultchoice = 1;
  
  int choice = defaultchoice;

  if (argc > 1) {
    if(sscanf(argv[1], "%d", &choice) != 1) {
      printf("Couldn't parse that input as a number\n");
      return -1;
    }
  }
  
  cout << "# math: repeating each test " << REPEAT << " times" << endl;
  
  randomizer.TimeSeed();

  cout << "# Testing MMFF94 Force Field..." << endl;
  switch(choice) {
  case 1:
    TEST( testBasics_vector3 );
    TEST( testBasics_matrix3x3 );
    break;
  case 2:
    TEST( testArithmeticOperators );
    TEST( testDistancesAnglesOrthogonality );
    break;
  case 3:
    TEST( testInversion );
    break;
  case 4:
    TEST( testEigenvalues );
    TEST( testEigenvectors );
    break;
  default:
    cout << "Test number " << choice << " does not exist!\n";
    return -1;
  }

  cout << "1.." << testCount << endl;

  if( failedCount == 0 ) cout << "# math: all tests are successful" << endl;
  else cout << "# math: " << failedCount << " out of "
            << testCount << " tests failed." << endl;
  return 0;
}
Beispiel #6
0
int main(int argc,char *argv[])
{
  if (argc != 2)
    {
      cout << "Usage: obrotamer <file>" << endl;
      cout << "  Outputs the number of rotable bonds and generate a random"
           << " rotamer" << endl;
      return(-1);
    }

  ifstream ifs(argv[1]);
  if (!ifs)
    {
      cerr << "Error! Cannot read input file!" << endl;
      return(-1);
    }
  
  OBConversion conv(&ifs, &cout);
  OBFormat* pFormat;
  
  pFormat = conv.FormatFromExt(argv[1]);
  if ( pFormat == NULL )
    {
      cerr << "Error! Cannot read file format!" << endl;
      return(-1);
    }
  
  // Finally, we can do some work!
  OBMol mol;
  if (! conv.SetInAndOutFormats(pFormat, pFormat))
    {
      cerr << "Error! File format isn't loaded" << endl;
      return (-1);
    }
  
  OBRotorList rl;
  OBRotamerList rotamers;
  int *rotorKey = NULL;
  OBRandom rand;
  rand.TimeSeed();

  while(ifs.peek() != EOF && ifs.good())
    {
      mol.Clear();
      conv.Read(&mol);

      rl.Setup(mol);
      
      cerr << " Number of rotatable bonds: " << rl.Size() << endl;

      // indexed from 1, rotorKey[0] = 0
      std::vector<int> rotorKey(rl.Size() + 1, 0);

      // each entry represents the configuration of a rotor
      // e.g. indexes into OBRotor::GetResolution()
      //       (the different angles to sample from the OBRotorRules database)
      OBRotorIterator ri;
      OBRotor *rotor = rl.BeginRotor(ri);
      for (int i = 1; i < rl.Size() + 1; ++i, rotor = rl.NextRotor(ri))
        rotorKey[i] = rand.NextInt() % rotor->GetResolution().size();

      rotamers.SetBaseCoordinateSets(mol);
      rotamers.Setup(mol, rl);
      rotamers.AddRotamer(rotorKey);

      // This is more useful when you have added many rotamers
      // rather than the one in this example
      rotamers.ExpandConformerList(mol, mol.GetConformers());
      
      // Change the molecule conformation -- from 0 .. rotamers.NumRotamers()
      mol.SetConformer(0);
      conv.Write(&mol);
    } // while reading molecules
  
  return(0);
}
Beispiel #7
0
void pickRandom( double & d )
{
  d = randomizer.NextFloat() * 2.0 - 1.0;
}