org.openmolecules.chem.conf.gen.TorsionSetStrategyLikelySystematic Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openchemlib Show documentation
Show all versions of openchemlib Show documentation
Open Source Chemistry Library
/*
* Copyright 2013-2020 Thomas Sander, openmolecules.org
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Thomas Sander
*/
package org.openmolecules.chem.conf.gen;
import java.util.Arrays;
/**
* TorsionSetStrategy that systematically creates all possible TorsionSets in
* batches while keeping a focus on the likelyhood of individual torsions.
* @author Thomas Sander
*/
public class TorsionSetStrategyLikelySystematic extends TorsionSetStrategy {
private int[] mCurrentMaxTorsionIndex,mCurrentMaxConformerIndex;
private TorsionSet[] mAvailableTorsionSet;
private int mAvailableTorsionSetIndex;
public TorsionSetStrategyLikelySystematic(ConformerGenerator conformerGenerator) {
super(conformerGenerator);
mCurrentMaxTorsionIndex = new int[mRotatableBond.length];
mCurrentMaxConformerIndex = new int[mRigidFragment.length];
mAvailableTorsionSet = new TorsionSet[1];
mAvailableTorsionSet[0] = createTorsionSet(new int[mRotatableBond.length], new int[mRigidFragment.length]);
mAvailableTorsionSetIndex = -1;
}
/**
* Determine the next likely set of torsion angles and return the TorsionSet
* containing an array of indexes referring to the torsion value in the
* RotatableBond and containing the contribution of this conformer to all
* non colliding ones.
* @return
*/
@Override
public TorsionSet createTorsionSet(TorsionSet previousTorsionSet) {
if (mAvailableTorsionSet == null)
return null;
if (mAvailableTorsionSetIndex + 1 == mAvailableTorsionSet.length)
createNextAvailableSet();
if (mAvailableTorsionSet == null)
return null;
mAvailableTorsionSetIndex++;
return mAvailableTorsionSet[mAvailableTorsionSetIndex];
}
private void createNextAvailableSet() {
int bestIndex = -1;
boolean isConformerIndex = false;
double minLoss = Double.MAX_VALUE;
BaseConformer baseConformer = mConformerGenerator.getBaseConformer(mCurrentMaxConformerIndex);
for (int rb=0; rb loss) {
minLoss = loss;
bestIndex = rb;
}
}
}
for (int rf=0; rf loss) {
minLoss = loss;
bestIndex = rf;
isConformerIndex = true;
}
}
}
if (bestIndex == -1) { // no unused torsion set remaining
mAvailableTorsionSet = null;
return;
}
int count = 1;
for (int i=0; i {
return Double.compare(ts2.getContribution(), ts1.getContribution()); // we want the highest likelyhood first
} );
mAvailableTorsionSetIndex = -1;
}
}