com.actelion.research.chem.shredder.Fragmenter3D 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
package com.actelion.research.chem.shredder;
import com.actelion.research.chem.Canonizer;
import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.conf.TorsionDB;
import com.actelion.research.chem.conf.TorsionDescriptor;
import com.actelion.research.chem.conf.TorsionDescriptorHelper;
import com.actelion.research.util.IntArrayComparator;
import java.util.ArrayList;
import java.util.TreeSet;
public class Fragmenter3D {
private int mMinAtoms,mMaxAtoms,mMaxBonds,mMinExits,mMaxExits;
private ArrayList mFragmentList;
/**
*
* @param minAtoms
* @param maxAtoms
* @param maxBonds
* @param minExits
* @param maxExits
*/
public Fragmenter3D(int minAtoms, int maxAtoms, int maxBonds, int minExits, int maxExits) {
mMinAtoms = minAtoms;
mMaxAtoms = maxAtoms;
mMaxBonds = maxBonds;
mMinExits = minExits;
mMaxExits = maxExits;
mFragmentList = new ArrayList<>();
}
/**
* Applying the constraints passed to the Fragmenter3D constructor, this method shredders
* the given 3D-molecule and returns all generated 3D-fragments as an ArrayList.
* The list is re-used by subsequent calls to this nethod. Thus, process/consume the
* fragment list before calling this method again.
* @param mol
* @return Fragment3D list of passed molecule
*/
public ArrayList getFragments(StereoMolecule mol) {
mFragmentList.clear();
mol.stripSmallFragments();
mol.removeExplicitHydrogens(false, true);
boolean[] isRotatableBond = new boolean[mol.getAllBonds()];
int count = TorsionDB.findRotatableBonds(mol, true, isRotatableBond);
int[] fragmentNo = new int[mol.getAllAtoms()];
int fragmentCount = mol.getFragmentNumbers(fragmentNo, isRotatableBond, true);
int[] atomCount = new int[fragmentCount];
for (int atom=0; atom baseFragmentCombinationSet = new TreeSet<>(new IntArrayComparator());
boolean[] isMemberFragment = new boolean[fragmentCount];
for (int i=0; i baseFragmentCombinationSet, Fragment3DData[] fragmentData) {
if (usedBaseFragmentCount - mMaxBonds > 1 || atomCount > mMaxAtoms)
return;
int[] baseFragmentList = new int[usedBaseFragmentCount];
int index = 0;
for (int i=0; i= mMinAtoms)
addFragment(mol, fragmentNo, isMemberFragment);
for (int neighbour:fragmentData[previousBaseFragment].neighbourFragment) {
if (!isMemberFragment[neighbour]) {
isMemberFragment[neighbour] = true;
addNewFragments(mol, fragmentNo, isMemberFragment, neighbour,
usedBaseFragmentCount+1, atomCount+fragmentData[neighbour].atomCount, baseFragmentCombinationSet, fragmentData);
isMemberFragment[neighbour] = false;
}
}
}
private void addFragment(StereoMolecule mol, int[] fragmentNo, boolean[] isMemberFragment) {
int atomCount = 0;
int extendedAtomCount = 0;
// mark all atoms with specified fragmentNo and two layers around it
boolean[] includeAtom = new boolean[mol.getAllAtoms()];
boolean[] isExitAtom = new boolean[mol.getAllAtoms()];
for (int atom=0; atom mMaxExits)
return;
int bondCount = 0;
for (int bond=0; bond