use of org.openscience.cdk.stereo.DoubleBondStereochemistry 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.DoubleBondStereochemistry in project ambit-mirror by ideaconsult.
the class SMIRKSManager method checkInvalidatedDBStereo.
public void checkInvalidatedDBStereo(IAtomContainer target, List<IStereoElement> invalidatedStereoElements, Map<IStereoElement, StereoChange> stereoChanges) {
// This check is needed since it is possible that the double stereo element is
// invalid but the stereo information is still present
// This happens when the a ligand atom is deleted (i.e. the element is invalidated)
// but there is another neighbor atom attached to the double bond which can be used
// to restore the stereo information
List<IStereoElement> restoredElements = new ArrayList<IStereoElement>();
for (IStereoElement element : invalidatedStereoElements) {
if (element instanceof DoubleBondStereochemistry) {
DoubleBondStereochemistry dbsc = (DoubleBondStereochemistry) element;
StereoChange stChange = stereoChanges.get(element);
DoubleBondStereochemistry restored = StereoChemUtils.restoreDBStereo(target, dbsc, stChange);
if (restored != null)
restoredElements.add(restored);
}
}
if (!restoredElements.isEmpty()) {
List<IStereoElement> newStereo = new ArrayList<IStereoElement>();
for (IStereoElement element : target.stereoElements()) newStereo.add(element);
newStereo.addAll(restoredElements);
target.setStereoElements(newStereo);
}
}
use of org.openscience.cdk.stereo.DoubleBondStereochemistry in project ambit-mirror by ideaconsult.
the class IsomorphismTester method matchDoubleBondStereo.
boolean matchDoubleBondStereo(SMARTSBond bond, Node node) {
DoubleBondStereoInfo dbsi = null;
if (bond instanceof DoubleNonAromaticBond)
dbsi = ((DoubleNonAromaticBond) bond).getStereoInfo();
else if (bond instanceof DoubleBondAromaticityNotSpecified)
dbsi = ((DoubleBondAromaticityNotSpecified) bond).getStereoInfo();
else if (bond instanceof SmartsBondExpression)
dbsi = ((SmartsBondExpression) bond).getStereoInfo();
if (dbsi == null)
// no stereo check is done;
return true;
int query_index0 = query.getAtomNumber(bond.getAtom(0));
int query_index1 = query.getAtomNumber(bond.getAtom(1));
int query_ligand0 = query.getAtomNumber(dbsi.ligand1);
int query_ligand1 = query.getAtomNumber(dbsi.ligand2);
IAtom targetAt0 = node.atoms[query_index0];
IAtom targetAt1 = node.atoms[query_index1];
IAtom targetLigand0 = node.atoms[query_ligand0];
IAtom targetLigand1 = node.atoms[query_ligand1];
// System.out.println("query double bond atoms: "+ query_index0 + " " +
// query_index1);
// System.out.println("query ligand atoms: "+ query_ligand0 + " " +
// query_ligand1);
// System.out.println("Target double bond atoms: "+
// target.getAtomNumber(targetAt0) + " " + target.getAtomNumber(targetAt1));
// System.out.println("Target ligand atoms: "+
// target.getAtomNumber(targetLigand0) + " " +
// target.getAtomNumber(targetLigand1));
IBond targetBo = target.getBond(targetAt0, targetAt1);
if (// this should never happen
targetBo == null) {
if (dbsi.conformation == DBStereo.OPPOSITE_OR_UNDEFINED || dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED)
return true;
return false;
}
// Find target double bond stereo element
DoubleBondStereochemistry element = null;
for (IStereoElement el : target.stereoElements()) {
if (el instanceof DoubleBondStereochemistry)
if (((DoubleBondStereochemistry) el).getStereoBond() == targetBo) {
element = (DoubleBondStereochemistry) el;
break;
}
}
if (element == null) {
if (dbsi.conformation == DBStereo.OPPOSITE_OR_UNDEFINED || dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED)
return true;
return false;
}
int nMatchedLigands = 0;
IBond[] elementBonds = element.getBonds();
if (elementBonds[0].contains(targetLigand0) || elementBonds[1].contains(targetLigand0))
nMatchedLigands++;
if (elementBonds[0].contains(targetLigand1) || elementBonds[1].contains(targetLigand1))
nMatchedLigands++;
if (nMatchedLigands == 1) {
if (element.getStereo() == Conformation.OPPOSITE) {
if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
return true;
else
return false;
} else {
// element.getStereo() == Conformation.TOGETHER
if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
return false;
else
return true;
}
} else {
if (element.getStereo() == Conformation.OPPOSITE) {
if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
return false;
else
return true;
} else {
// element.getStereo() == Conformation.TOGETHER
if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
return true;
else
return false;
}
}
}
use of org.openscience.cdk.stereo.DoubleBondStereochemistry 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.DoubleBondStereochemistry in project ambit-mirror by ideaconsult.
the class StereoChemUtils method cloneDoubleBondStereochemistry.
/**
* @param originalDBS - the stereo element from the original molecule that will be cloned
* @param originalMol - the original molecule
* @param cloneMol - the clone molecule. Its atoms and bond must have already be cloned
* @param newAtoms - the cloned/new atoms
* @param newBonds - the cloned/new bonds
* @return
*/
public static DoubleBondStereochemistry cloneDoubleBondStereochemistry(DoubleBondStereochemistry originalDBS, IAtomContainer originalMol, IAtomContainer cloneMol, IAtom[] newAtoms, IBond[] newBonds) {
if (originalDBS.getStereoBond() == null)
return null;
int steroBondNum = originalMol.getBondNumber(originalDBS.getStereoBond());
IBond[] bonds0 = originalDBS.getBonds();
if (bonds0 == null)
return null;
IBond[] bonds = new IBond[bonds0.length];
for (int i = 0; i < bonds0.length; i++) {
int boNum = originalMol.getBondNumber(bonds0[i]);
bonds[i] = newBonds[boNum];
}
DoubleBondStereochemistry dbs = new DoubleBondStereochemistry(newBonds[steroBondNum], bonds, originalDBS.getStereo());
return dbs;
}
Aggregations