use of org.openscience.cdk.stereo.TetrahedralChirality in project ambit-mirror by ideaconsult.
the class SMIRKSManager method getCloneStructure.
IAtomContainer getCloneStructure(IAtomContainer target) throws Exception {
IAtomContainer mol = new AtomContainer();
IAtom[] newAtoms = new IAtom[target.getAtomCount()];
IBond[] newBonds = new IBond[target.getBondCount()];
// Clone atoms
for (int i = 0; i < target.getAtomCount(); i++) {
IAtom a = target.getAtom(i);
IAtom a1 = cloneAtom(a);
mol.addAtom(a1);
newAtoms[i] = a1;
}
// Clone bonds
for (int i = 0; i < target.getBondCount(); i++) {
IBond b = target.getBond(i);
IBond b1 = MoleculeTools.newBond(target.getBuilder());
IAtom[] a01 = new IAtom[2];
int ind0 = target.getAtomNumber(b.getAtom(0));
int ind1 = target.getAtomNumber(b.getAtom(1));
a01[0] = mol.getAtom(ind0);
a01[1] = mol.getAtom(ind1);
b1.setAtoms(a01);
b1.setOrder(b.getOrder());
boolean FlagArom = b.getFlag(CDKConstants.ISAROMATIC);
b1.setFlag(CDKConstants.ISAROMATIC, FlagArom);
mol.addBond(b1);
newBonds[i] = b1;
}
// Clone stereo elements
for (IStereoElement element : target.stereoElements()) {
if (element instanceof DoubleBondStereochemistry) {
DoubleBondStereochemistry dbs0 = (DoubleBondStereochemistry) element;
DoubleBondStereochemistry dbs = StereoChemUtils.cloneDoubleBondStereochemistry(dbs0, target, mol, newAtoms, newBonds);
if (dbs != null)
mol.addStereoElement(dbs);
continue;
}
if (element instanceof TetrahedralChirality) {
TetrahedralChirality thc0 = (TetrahedralChirality) element;
TetrahedralChirality thc = StereoChemUtils.cloneTetrahedralChirality(thc0, target, mol, newAtoms);
if (thc != null)
mol.addStereoElement(thc);
continue;
}
// TODO handle ExtendedTetrahedral (... allene like chiral centers)
}
return mol;
}
use of org.openscience.cdk.stereo.TetrahedralChirality in project ambit-mirror by ideaconsult.
the class IsomorphismTester method getTargetChiralAtomStereo.
int getTargetChiralAtomStereo(SmartsAtomExpression atom, Node node) {
int queryChiralCenter_index = query.getAtomNumber(atom);
IAtom targetCenter = node.atoms[queryChiralCenter_index];
if (atom.extChirInfo == null) {
// Handle chiral stereo center
TetrahedralChirality thc = findTargetChiralStereoElement(targetCenter);
if (thc == null)
return SmartsConst.ChC_Unspec;
IAtom[] targetMatchedLigands = new IAtom[atom.stereoLigands.size()];
for (int i = 0; i < targetMatchedLigands.length; i++) {
int query_index = query.getAtomNumber(atom.stereoLigands.get(i));
targetMatchedLigands[i] = node.atoms[query_index];
}
if (atom.hasImplicitHStereoLigand) {
// The targetCenter must be within target ligands
boolean FlagOK = false;
for (int i = 0; i < targetMatchedLigands.length; i++) {
if (targetMatchedLigands[i] == targetCenter) {
FlagOK = true;
break;
}
}
if (!FlagOK)
// This case should not occur if target stereo element is OK
return SmartsConst.ChC_Unspec;
}
// ligands as defined in the target molecule.
IAtom[] targetOriginalLigands = thc.getLigands();
// (additional checks are done below as well)
if (targetOriginalLigands == null)
return SmartsConst.ChC_Unspec;
if (targetOriginalLigands.length != 4)
return SmartsConst.ChC_Unspec;
// Determining the target ligands permutation as well as
// checking the correctness of the target stereo element (there is a chance that
// the target stereo element is no correct - in this case the result is
// ChC_Unspec)
// The query ligands order is considered to be the basic permutation (0,1,2,3)
int[] targetPerm = new int[4];
for (int i = 0; i < targetMatchedLigands.length; i++) {
int pos = getLigandIndex(targetMatchedLigands[i], targetOriginalLigands);
if (pos == -1)
return SmartsConst.ChC_Unspec;
// This means incorrect target ligands in the stereo element.
// Neighbor to the targer center is matched which is not within
// The stereo element ligang list.
// This error should not appear but if present it is due to
// incorrect target AtomContainer object
targetPerm[i] = pos;
}
int nSwitches = ChiralPermutations.getNumOfPairSwitches(ChiralPermutations.basic4Permutation, targetPerm);
if ((nSwitches % 2) == 0) {
// relative stereo configurations are the same
if (thc.getStereo() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
return SmartsConst.ChC_AntiClock;
else
return SmartsConst.ChC_Clock;
} else {
// relative stereo configurations are different
if (thc.getStereo() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
return SmartsConst.ChC_Clock;
else
return SmartsConst.ChC_AntiClock;
}
} else {
// Handle extended chirality
ExtendedTetrahedral exth = findTargetExtendedTetrahedralElement(targetCenter);
if (exth == null)
return SmartsConst.ChC_Unspec;
IAtom[] targetMatchedLigands = new IAtom[atom.stereoLigands.size()];
for (int i = 0; i < targetMatchedLigands.length; i++) {
int query_index = query.getAtomNumber(atom.stereoLigands.get(i));
targetMatchedLigands[i] = node.atoms[query_index];
}
// peripherals (ligands) as defined in the target molecule.
IAtom[] targetOriginalLigands = exth.peripherals();
// (additional checks are done below as well)
if (targetOriginalLigands == null)
return SmartsConst.ChC_Unspec;
if (targetOriginalLigands.length != 4)
return SmartsConst.ChC_Unspec;
// Determining the target ligands permutation as well as
// checking the correctness of the target stereo element (there is a chance that
// the target stereo element is no correct - in this case the result is
// ChC_Unspec)
// The query ligands order is considered to be the basic permutation (0,1,2,3)
int[] targetPerm = new int[4];
for (int i = 0; i < targetMatchedLigands.length; i++) {
int pos = getLigandIndex(targetMatchedLigands[i], targetOriginalLigands);
if (pos == -1)
return SmartsConst.ChC_Unspec;
// This means incorrect target ligands in the stereo element.
// Neighbor to the targer center is matched which is not within
// The stereo element ligang list.
// This error should not appear but if present it is due to
// incorrect target IAtomContainer object
targetPerm[i] = pos;
}
int nSwitches = ChiralPermutations.getNumOfPairSwitches(ChiralPermutations.basic4Permutation, targetPerm);
if ((nSwitches % 2) == 0) {
// relative stereo configurations are the same
if (exth.winding() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
return SmartsConst.ChC_AntiClock;
else
return SmartsConst.ChC_Clock;
} else {
// relative stereo configurations are different
if (exth.winding() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
return SmartsConst.ChC_Clock;
else
return SmartsConst.ChC_AntiClock;
}
}
}
use of org.openscience.cdk.stereo.TetrahedralChirality in project ambit-mirror by ideaconsult.
the class StereoChemUtils method getAllStereoElementsStatus.
public static String getAllStereoElementsStatus(IAtomContainer mol, List<IStereoElement> invElements) {
StringBuffer sb = new StringBuffer();
sb.append(" Normal elements \n");
for (IStereoElement element : mol.stereoElements()) {
if (element instanceof DoubleBondStereochemistry) {
int status = checkDoubleBondStereochemistry((DoubleBondStereochemistry) element, mol);
sb.append(" DBStereo status = " + status + " " + doubleBondStereochemistry2String((DoubleBondStereochemistry) element, mol) + "\n");
continue;
}
if (element instanceof TetrahedralChirality) {
int status = checkTetrahedralChirality((TetrahedralChirality) element, mol);
sb.append(" Chiral atom status = " + status + " " + tetrahedralChirality2String((TetrahedralChirality) element, mol) + "\n");
continue;
}
// TODO handle ExtendedTetrahedral stereo elements
}
sb.append(" Invalidated elements \n");
for (IStereoElement element : invElements) {
if (element instanceof DoubleBondStereochemistry) {
int status = checkDoubleBondStereochemistry((DoubleBondStereochemistry) element, mol);
sb.append(" DBStereo status = " + status + " " + doubleBondStereochemistry2String((DoubleBondStereochemistry) element, mol) + "\n");
continue;
}
if (element instanceof TetrahedralChirality) {
int status = checkTetrahedralChirality((TetrahedralChirality) element, mol);
sb.append(" Chiral atom status = " + status + " " + tetrahedralChirality2String((TetrahedralChirality) element, mol) + "\n");
continue;
}
// TODO handle ExtendedTetrahedral stereo elements
}
return sb.toString();
}
use of org.openscience.cdk.stereo.TetrahedralChirality in project ambit-mirror by ideaconsult.
the class StereoChemUtils method cloneTetrahedralChirality.
/*
* Cloning based on presumption that atom/bond indices define
* the atom mapping between original and clone molecule
*/
public static TetrahedralChirality cloneTetrahedralChirality(TetrahedralChirality originalTHC, IAtomContainer originalMol, IAtomContainer cloneMol) {
IAtom chiralAtom = originalTHC.getChiralAtom();
if (chiralAtom == null)
return null;
int chiralAtomNum = originalMol.getAtomNumber(chiralAtom);
IAtom[] ligands0 = originalTHC.getLigands();
if (ligands0 == null)
return null;
IAtom[] ligands = new IAtom[ligands0.length];
for (int i = 0; i < ligands0.length; i++) {
int atNum = originalMol.getAtomNumber(ligands0[i]);
ligands[i] = cloneMol.getAtom(atNum);
}
TetrahedralChirality thc = new TetrahedralChirality(cloneMol.getAtom(chiralAtomNum), ligands, originalTHC.getStereo());
return thc;
}
use of org.openscience.cdk.stereo.TetrahedralChirality in project ambit-mirror by ideaconsult.
the class StereoChemUtils method getStereoElementsStatus.
public static String getStereoElementsStatus(IAtomContainer mol) {
StringBuffer sb = new StringBuffer();
List<IStereoElement> okElements = new ArrayList<IStereoElement>();
for (IStereoElement element : mol.stereoElements()) {
if (element instanceof DoubleBondStereochemistry) {
int status = checkDoubleBondStereochemistry((DoubleBondStereochemistry) element, mol);
sb.append("DBStereo status = " + status + " " + doubleBondStereochemistry2String((DoubleBondStereochemistry) element, mol) + "\n");
continue;
}
if (element instanceof TetrahedralChirality) {
int status = checkTetrahedralChirality((TetrahedralChirality) element, mol);
sb.append("Chiral atom status = " + status + " " + tetrahedralChirality2String((TetrahedralChirality) element, mol) + "\n");
continue;
}
// TODO handle ExtendedTetrahedral stereo elements
}
return sb.toString();
}
Aggregations