com.actelion.research.chem.contrib.HoseCodeCreator 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.contrib;
import java.util.Arrays;
import java.util.Vector;
import com.actelion.research.chem.Canonizer;
import com.actelion.research.chem.ExtendedMolecule;
import com.actelion.research.chem.IDCodeParser;
import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.StereoMolecule;
public class HoseCodeCreator {
public final static int FULL_HOSE_CODE=0;
public final static int HOSE_CODE_CUT_C_SP3_SP3=1;
final static boolean DEBUG=false;
/**
* 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 static String[][] getHoseCodes(StereoMolecule mol, int maxSphereSize, int type) {
String[][] ids=new String[mol.getAtoms()][maxSphereSize];
mol.ensureHelperArrays(Molecule.cHelperRings);
for (int rootAtom=0; rootAtom ids=new Vector();
int min = 0;
int max = 0;
boolean[] atomMask = new boolean[mol.getAtoms()];
int[] atomList = new int[mol.getAtoms()];
for (int sphere=0; sphere "+atom+" to "+connAtom);
if (!atomMask[connAtom]) {
switch (type) {
case FULL_HOSE_CODE:
atomMask[connAtom] = true;
atomList[newMax++] = connAtom;
break;
case HOSE_CODE_CUT_C_SP3_SP3:
if ( ! (isCsp3(mol, atom) && isCsp3(mol,connAtom))) {
if (DEBUG) System.out.println("NO SKIP");
atomMask[connAtom] = true;
atomList[newMax++] = connAtom;
} else {
if (DEBUG) System.out.println("SKIP");
}
break;
}
}
}
}
min = max;
max = newMax;
}
mol.copyMoleculeByAtoms(fragment, atomMask, true, null);
// TO GET ONLY THE SKELETON
/*
for (int atom=0; atom=0) {
return HoseCodeCreator.getHoseCodesForAtom(molecule, atomID, maxSphereSize, type);
}
return new String[0];
}
public static void main(String[] args) {
StereoMolecule molecule= new IDCodeParser(false).getCompactMolecule("deT@@DjU_k``b`@@");
StereoMolecule otherMolecule = new StereoMolecule(molecule.getAtoms(), molecule.getBonds());
boolean[] atomMask = new boolean[molecule.getAtoms()];
Arrays.fill(atomMask, true);
molecule.copyMoleculeByAtoms(otherMolecule, atomMask, true, null);
System.out.println(new Canonizer(otherMolecule, Canonizer.ENCODE_ATOM_CUSTOM_LABELS).getIDCode());
// String id="deT@`@f\bbbRK]@PT@@";
String id="fi{qa@DyZkQPSI`cHhhdhdhddhekF\\\\fNXBBjfjjjaXTh@RB@QJh";
String[] hoses= HoseCodeCreator.getHoseCodesFromDiaID(id, 20, FULL_HOSE_CODE);
for (int i=0; i