use of com.actelion.research.util.datamodel.IntVec in project openchemlib by Actelion.
the class DescriptorHandlerHashedCFp method createDescriptor.
/**
* This descriptor requires proper up/down bonds, because it encodes stereo parities.
* If a passed molecule is generated from idcode parsing, make sure that coordinates
* and up/down/bonds are available, i.e. that the IDCodeParser was instantiated with
* the respective option.
*/
public int[] createDescriptor(StereoMolecule mol) {
if (mol == null)
return null;
mol.ensureHelperArrays(Molecule.cHelperRings);
StereoMolecule fragment = new StereoMolecule(mol.getAtoms(), mol.getBonds());
// byte[] descriptor = new byte[DESCRIPTOR_SIZE];
int len = DESCRIPTOR_SIZE / Integer.SIZE;
IntVec iv = new IntVec(len);
int[] atomList = new int[mol.getAtoms()];
boolean[] atomMask = new boolean[mol.getAtoms()];
for (int rootAtom = 0; rootAtom < mol.getAtoms(); rootAtom++) {
if (rootAtom != 0)
Arrays.fill(atomMask, false);
int min = 0;
int max = 0;
for (int sphere = 0; sphere < SPHERE_COUNT && max < mol.getAtoms(); sphere++) {
if (max == 0) {
atomList[0] = rootAtom;
atomMask[rootAtom] = true;
max = 1;
} else {
int newMax = max;
for (int i = min; i < max; i++) {
int atom = atomList[i];
for (int j = 0; j < mol.getConnAtoms(atom); j++) {
int connAtom = mol.getConnAtom(atom, j);
if (!atomMask[connAtom]) {
atomMask[connAtom] = true;
atomList[newMax++] = connAtom;
}
}
}
min = max;
max = newMax;
}
mol.copyMoleculeByAtoms(fragment, atomMask, true, null);
// take fragment as it is
String idcode = new Canonizer(fragment).getIDCode();
int h = BurtleHasher.hashlittle(idcode, HASH_INIT);
h = (h & BurtleHasher.hashmask(HASH_BITS));
iv.setBit(h);
// System.out.println("atom:"+rootAtom+"\tsphere:"+sphere+"\thash:"+h+"\t"+idcode);
}
}
return iv.get();
}
Aggregations