/// <summary> Converts a RingSet to an AtomContainer. /// /// </summary> /// <param name="ringSet"> The RingSet to be converted. /// </param> /// <returns> The AtomContainer containing the bonds and atoms of the ringSet. /// </returns> public static IAtomContainer convertToAtomContainer(IRingSet ringSet) { IRing ring = (IRing)ringSet.getAtomContainer(0); if (ring == null) { return(null); } IAtomContainer ac = ring.Builder.newAtomContainer(); for (int i = 0; i < ringSet.AtomContainerCount; i++) { ring = (IRing)ringSet.getAtomContainer(i); for (int r = 0; r < ring.getBondCount(); r++) { IBond bond = ring.getBondAt(r); if (!ac.contains(bond)) { for (int j = 0; j < bond.AtomCount; j++) { ac.addAtom(bond.getAtomAt(j)); } ac.addBond(bond); } } } return(ac); }
public static bool replaceAtomByAtom(IAtomContainer container, IAtom atom, IAtom newAtom) { if (!container.contains(atom)) { // it should complain return(false); } else { container.setAtomAt(container.getAtomNumber(atom), newAtom); IElectronContainer[] electronContainers = container.ElectronContainers; for (int i = 0; i < electronContainers.Length; i++) { if (electronContainers[i] is IBond) { IBond bond = (IBond)electronContainers[i]; if (bond.contains(atom)) { for (int j = 0; j < bond.AtomCount; j++) { if (atom.Equals(bond.getAtomAt(j))) { bond.setAtomAt(newAtom, j); } } } } else if (electronContainers[i] is ILonePair) { ILonePair lonePair = (ILonePair)electronContainers[i]; if (atom.Equals(lonePair.Atom)) { lonePair.Atom = newAtom; } } } return(true); } }
public static void removeElectronContainer(ISetOfAtomContainers set_Renamed, IElectronContainer electrons) { IAtomContainer[] acs = set_Renamed.AtomContainers; for (int i = 0; i < acs.Length; i++) { IAtomContainer container = acs[i]; if (container.contains(electrons)) { container.removeElectronContainer(electrons); IMolecule[] molecules = ConnectivityChecker.partitionIntoMolecules(container).Molecules; if (molecules.Length > 1) { set_Renamed.removeAtomContainer(container); for (int k = 0; k < molecules.Length; k++) { set_Renamed.addAtomContainer(molecules[k]); } } return; } } }
public static bool replaceAtomByAtom(IAtomContainer container, IAtom atom, IAtom newAtom) { if (!container.contains(atom)) { // it should complain return false; } else { container.setAtomAt(container.getAtomNumber(atom), newAtom); IElectronContainer[] electronContainers = container.ElectronContainers; for (int i = 0; i < electronContainers.Length; i++) { if (electronContainers[i] is IBond) { IBond bond = (IBond)electronContainers[i]; if (bond.contains(atom)) { for (int j = 0; j < bond.AtomCount; j++) { if (atom.Equals(bond.getAtomAt(j))) { bond.setAtomAt(newAtom, j); } } } } else if (electronContainers[i] is ILonePair) { ILonePair lonePair = (ILonePair)electronContainers[i]; if (atom.Equals(lonePair.Atom)) { lonePair.Atom = newAtom; } } } return true; } }