use of org.openscience.cdk.interfaces.IStereoElement in project ambit-mirror by ideaconsult.
the class SuppleAtomContainer method init.
protected void init() {
atoms = new FilteredList<IAtom>();
bonds = new FilteredList<IBond>();
lonePairs = new ArrayList<ILonePair>();
singleElectrons = new ArrayList<ISingleElectron>();
int atomCount = getAtomCount();
stereoElements = new HashSet<IStereoElement>(atomCount / 2);
for (IStereoElement element : stereoElements()) {
addStereoElement(element);
}
}
use of org.openscience.cdk.interfaces.IStereoElement 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.interfaces.IStereoElement in project ambit-mirror by ideaconsult.
the class SMIRKSManager method deleteAtomAndDoStereoTransformation.
void deleteAtomAndDoStereoTransformation(IAtom tAt, IAtomContainer target, List<IStereoElement> invalidatedStereoElements, Map<IStereoElement, StereoChange> stereoChanges) {
// Preliminary store the elements that are to be changed by the atom deletion
// and hence to be removed from the IAtomContainer object
// by function removeAtomAndConnectedElectronContainers()
List<IStereoElement> listSE = getStereoElementsToBeRemoved(tAt, target);
target.removeAtomAndConnectedElectronContainers(tAt);
// Check previously invalidated stereo elements
if (!invalidatedStereoElements.isEmpty()) {
List<IStereoElement> newInvEl = new ArrayList<IStereoElement>();
for (IStereoElement stEl : invalidatedStereoElements) {
if (StereoChemUtils.contains(stEl, tAt)) {
StereoChange stChange = stereoChanges.get(stEl);
stereoChanges.remove(stEl);
// System.out.println(" ## handleStereoOnAtomDeletion");
IStereoElement el = handleStereoOnAtomDeletion(tAt, target, stEl, stChange);
// if el = null then the stereo element is for 'total removal'
if (el != null) {
newInvEl.add(el);
stereoChanges.put(el, stChange);
}
} else
// no change to the invalidated element
newInvEl.add(stEl);
}
invalidatedStereoElements.clear();
invalidatedStereoElements.addAll(newInvEl);
}
// Handle newly invalidated stereo elements
if (!listSE.isEmpty()) {
for (IStereoElement stEl : listSE) {
StereoChange stChange = stereoChanges.get(stEl);
stereoChanges.remove(stEl);
// System.out.println(" >> handleStereoOnAtomDeletion");
// System.out.println(" >> " + StereoChemUtils.stereoElement2String(stEl, target));
// System.out.println(" >> StereoChange: " + stChange.toString(target));
IStereoElement el = handleStereoOnAtomDeletion(tAt, target, stEl, stChange);
// if el = null then the stereo element is for 'total removal'
if (el != null) {
invalidatedStereoElements.add(el);
stereoChanges.put(el, stChange);
}
}
}
}
use of org.openscience.cdk.interfaces.IStereoElement 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.interfaces.IStereoElement 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;
}
}
}
Aggregations