/// <summary> /// RemovePseudoAtoms /// </summary> /// <param name="mol"></param> /// <returns>Pseudo atom count</returns> public static int RemovePseudoAtoms(IAtomContainer mol) { List <IAtom> pseudoAtoms = new List <IAtom>(); for (int ai = 0; ai < mol.getAtomCount(); ai++) { IAtom atom = mol.getAtom(ai); if (atom is IPseudoAtom) { pseudoAtoms.Add(atom); } } if (pseudoAtoms.Count == 0) { return(0); } foreach (IAtom atom in pseudoAtoms) { mol.removeAtomAndConnectedElectronContainers(atom); } AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); mol = AtomContainerManipulator.suppressHydrogens(mol); GetHydrogenAdder().addImplicitHydrogens(mol); return(pseudoAtoms.Count); }
/// <summary> /// Remove the following features from a molecule /// - Atom non-standard mass /// - Stereo chemistry /// - explicit hydrogens /// </summary> /// <param name="src"></param> /// <returns>Modified mol</returns> public static IAtomContainer RemoveIsotopesStereoExplicitHydrogens( IAtomContainer src) { IAtom[] atoms = new IAtom[src.getAtomCount()]; IBond[] bonds = new IBond[src.getBondCount()]; IChemObjectBuilder builder = src.getBuilder(); for (int i = 0; i < atoms.Length; i++) { IAtom atom = src.getAtom(i); IAtom atom2 = (IAtom)builder.newInstance(typeof(IAtom), atom.getSymbol()); SetImplicitHydrogenCount(atom2, GetImplicitHydrogenCount(atom)); atom2.setPoint2d(atom.getPoint2d()); atoms[i] = atom2; } for (int i = 0; i < bonds.Length; i++) { IBond bond = src.getBond(i); int u = src.getAtomNumber(bond.getAtom(0)); int v = src.getAtomNumber(bond.getAtom(1)); IBond bond2 = (IBond)builder.newInstance(typeof(IBond), atoms[u], atoms[v]); bond2.setIsAromatic(bond.isAromatic()); bond2.setIsInRing(bond.isInRing()); bond2.setOrder(bond.getOrder()); bond2.setFlag(CDKConstants.ISAROMATIC, bond.getFlag(CDKConstants.ISAROMATIC)); bond2.setFlag(CDKConstants.SINGLE_OR_DOUBLE, bond.getFlag(CDKConstants.SINGLE_OR_DOUBLE)); bonds[i] = bond2; } IAtomContainer dest = (IAtomContainer)builder.newInstance(typeof(IAtomContainer)); dest.setAtoms(atoms); dest.setBonds(bonds); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(dest); dest = AtomContainerManipulator.suppressHydrogens(dest); GetHydrogenAdder().addImplicitHydrogens(dest); return(dest); }
/// <summary> /// Integrate MMP difference and common fragments /// </summary> /// <param name="smilesFrags"></param> /// <returns>Molfile of integrated mol with difference fragment hilighted via special atom isotope values </returns> public string IntegrateAndHilightMmpStructure( string smilesFrags) { IAtomContainer mol; IAtom atom; string frag, context1, context2, molfile, chime = "", molfile2 = ""; int ai, atomCount; //IsotopeConversionTest(""); // debug DateTime t0 = DateTime.Now; try { Lex.Split(smilesFrags, ":", out frag, out context1, out context2); if (Lex.Eq(context2, "NULL")) { context2 = ""; // fixup for undefined Redshift fragment smiles fragment represented as "NULL" rather than a blank string } mol = SmilesToAtomContainer(frag); atomCount = mol.getAtomCount(); for (ai = 0; ai < atomCount; ai++) // set isotope labels to mark difference frag { atom = mol.getAtom(ai); int mn = GetMassNumber(atom); if (mn == 0) { SetMassNumber(atom, hilightIsotopeValue); // mark with special value } else if (mn > 0) { SetMassNumber(atom, -mn); // negate original value to indicate part of difference frag } } if (Lex.IsDefined(context1)) { JoinMmpFragments(mol, context1, 1); atomCount = mol.getAtomCount(); } if (Lex.IsDefined(context2)) { JoinMmpFragments(mol, context2, 2); atomCount = mol.getAtomCount(); } mol = AtomContainerManipulator.suppressHydrogens(mol); // fix potential valency issues atomCount = mol.getAtomCount(); for (ai = 0; ai < atomCount; ai++) // clean up structure for good display { atom = mol.getAtom(ai); if (atom.getValency() != null && atom.getValency().intValue() != 0) { atom.setValency(new java.lang.Integer(0)); } if (GetImplicitHydrogenCount(atom) != 0) { SetImplicitHydrogenCount(atom, 0); } } AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); mol = AtomContainerManipulator.suppressHydrogens(mol); GetHydrogenAdder().addImplicitHydrogens(mol); mol = GenerateCoordinates(mol); atomCount = mol.getAtomCount(); molfile = ConvertIsotopeValuesToHilighting(mol); // about 3.0 ms per IntegrateAndHilightMmpStructure call double msTime = TimeOfDay.Delta(t0); IntegrateAndHilightMmpStructureCount++; IntegrateAndHilightMmpStructureTotalTime += msTime; IntegrateAndHilightMmpStructureAvgTime = IntegrateAndHilightMmpStructureTotalTime / IntegrateAndHilightMmpStructureCount; return(molfile); } catch (Exception ex) { string msg = "Error integrating Smiles Fragments: " + smilesFrags + DebugLog.FormatExceptionMessage(ex, true); DebugLog.Message(msg); return(""); } }