public virtual void saturateRingSystems(IAtomContainer atomContainer) { IRingSet rs = new SSSRFinder(atomContainer.Builder.newMolecule(atomContainer)).findSSSR(); System.Collections.ArrayList ringSets = RingPartitioner.partitionRings(rs); IAtomContainer ac = null; IAtom atom = null; int[] temp; for (int f = 0; f < ringSets.Count; f++) { rs = (IRingSet)ringSets[f]; ac = RingSetManipulator.getAllInOneContainer(rs); temp = new int[ac.AtomCount]; for (int g = 0; g < ac.AtomCount; g++) { atom = ac.getAtomAt(g); temp[g] = atom.getHydrogenCount(); atom.setHydrogenCount(atomContainer.getBondCount(atom) - ac.getBondCount(atom) - temp[g]); } saturate(ac); for (int g = 0; g < ac.AtomCount; g++) { atom = ac.getAtomAt(g); atom.setHydrogenCount(temp[g]); } } }
/// <summary> Method that saturates an atom in a molecule by adding implicit hydrogens. /// /// </summary> /// <param name="container"> Molecule to saturate /// </param> /// <param name="atom"> Atom to satureate. /// </param> /// <cdk.keyword> hydrogen, adding </cdk.keyword> /// <cdk.keyword> implicit hydrogen </cdk.keyword> public virtual int[] addImplicitHydrogensToSatisfyValency(IAtomContainer container, IAtom atom) { int formerHydrogens = atom.getHydrogenCount(); int missingHydrogens = valencyChecker.calculateNumberOfImplicitHydrogens(atom, container); atom.setHydrogenCount(missingHydrogens); int[] hydrogens = new int[2]; hydrogens[0] = formerHydrogens; hydrogens[1] = missingHydrogens; return(hydrogens); }
/// <summary> Method that saturates an atom in a molecule by adding explicit hydrogens. /// /// </summary> /// <param name="atom"> Atom to saturate /// </param> /// <param name="container">AtomContainer containing the atom /// </param> /// <param name="count"> Number of hydrogens to add /// </param> /// <param name="totalContainer">In case you have a container containing multiple structures, this is the total container, whereas container is a partial structure /// /// </param> /// <cdk.keyword> hydrogen, adding </cdk.keyword> /// <cdk.keyword> explicit hydrogen </cdk.keyword> public virtual IAtomContainer addExplicitHydrogensToSatisfyValency(IAtomContainer container, IAtom atom, int count, IAtomContainer totalContainer) { //boolean create2DCoordinates = GeometryTools.has2DCoordinates(container); IIsotope isotope = IsotopeFactory.getInstance(container.Builder).getMajorIsotope("H"); atom.setHydrogenCount(0); IAtomContainer changedAtomsAndBonds = container.Builder.newAtomContainer(); for (int i = 1; i <= count; i++) { IAtom hydrogen = container.Builder.newAtom("H"); IsotopeFactory.getInstance(container.Builder).configure(hydrogen, isotope); totalContainer.addAtom(hydrogen); IBond newBond = container.Builder.newBond((IAtom)atom, hydrogen, 1.0); totalContainer.addBond(newBond); changedAtomsAndBonds.addAtom(hydrogen); changedAtomsAndBonds.addBond(newBond); } return(changedAtomsAndBonds); }
/// <summary> Method that saturates an atom in a molecule by adding implicit hydrogens. /// /// </summary> /// <param name="container"> Molecule to saturate /// </param> /// <param name="atom"> Atom to satureate. /// </param> /// <cdk.keyword> hydrogen, adding </cdk.keyword> /// <cdk.keyword> implicit hydrogen </cdk.keyword> public virtual int[] addImplicitHydrogensToSatisfyValency(IAtomContainer container, IAtom atom) { int formerHydrogens = atom.getHydrogenCount(); int missingHydrogens = valencyChecker.calculateNumberOfImplicitHydrogens(atom, container); atom.setHydrogenCount(missingHydrogens); int[] hydrogens = new int[2]; hydrogens[0] = formerHydrogens; hydrogens[1] = missingHydrogens; return hydrogens; }
/// <summary> Method that saturates an atom in a molecule by adding explicit hydrogens. /// /// </summary> /// <param name="atom"> Atom to saturate /// </param> /// <param name="container">AtomContainer containing the atom /// </param> /// <param name="count"> Number of hydrogens to add /// </param> /// <param name="totalContainer">In case you have a container containing multiple structures, this is the total container, whereas container is a partial structure /// /// </param> /// <cdk.keyword> hydrogen, adding </cdk.keyword> /// <cdk.keyword> explicit hydrogen </cdk.keyword> public virtual IAtomContainer addExplicitHydrogensToSatisfyValency(IAtomContainer container, IAtom atom, int count, IAtomContainer totalContainer) { //boolean create2DCoordinates = GeometryTools.has2DCoordinates(container); IIsotope isotope = IsotopeFactory.getInstance(container.Builder).getMajorIsotope("H"); atom.setHydrogenCount(0); IAtomContainer changedAtomsAndBonds = container.Builder.newAtomContainer(); for (int i = 1; i <= count; i++) { IAtom hydrogen = container.Builder.newAtom("H"); IsotopeFactory.getInstance(container.Builder).configure(hydrogen, isotope); totalContainer.addAtom(hydrogen); IBond newBond = container.Builder.newBond((IAtom) atom, hydrogen, 1.0); totalContainer.addBond(newBond); changedAtomsAndBonds.addAtom(hydrogen); changedAtomsAndBonds.addBond(newBond); } return changedAtomsAndBonds; }
/// <summary> Procedure required by the CDOInterface. This function is only /// supposed to be called by the JCFL library /// </summary> public virtual void setObjectProperty(System.String objectType, System.String propertyType, System.String propertyValue) { //logger.debug("objectType: " + objectType); //logger.debug("propType: " + propertyType); //logger.debug("property: " + propertyValue); if (objectType == null) { //logger.error("Cannot add property for null object"); return; } if (propertyType == null) { //logger.error("Cannot add property for null property type"); return; } if (propertyValue == null) { //logger.warn("Will not add null property"); return; } if (objectType.Equals("Molecule")) { if (propertyType.Equals("id")) { currentMolecule.ID = propertyValue; } else if (propertyType.Equals("inchi")) { currentMolecule.setProperty("iupac.nist.chemical.identifier", propertyValue); } else if (propertyType.Equals("pdb:residueName")) { currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue); } else if (propertyType.Equals("pdb:oneLetterCode")) { currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue); } else if (propertyType.Equals("pdb:id")) { currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue); } else { //logger.warn("Not adding molecule property!"); } } else if (objectType.Equals("PseudoAtom")) { if (propertyType.Equals("label")) { if (!(currentAtom is IPseudoAtom)) { currentAtom = currentChemFile.Builder.newPseudoAtom(currentAtom); } ((IPseudoAtom)currentAtom).Label = propertyValue; } } else if (objectType.Equals("Atom")) { if (propertyType.Equals("type")) { if (propertyValue.Equals("R") && !(currentAtom is IPseudoAtom)) { currentAtom = currentChemFile.Builder.newPseudoAtom(currentAtom); } currentAtom.Symbol = propertyValue; } else if (propertyType.Equals("x2")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.X2d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("y2")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.Y2d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("x3")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.X3d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("y3")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.Y3d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("z3")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.Z3d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("xFract")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.FractX3d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("yFract")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.FractY3d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("zFract")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.FractZ3d = System.Double.Parse(propertyValue); } else if (propertyType.Equals("formalCharge")) { currentAtom.setFormalCharge(System.Int32.Parse(propertyValue)); } else if (propertyType.Equals("charge") || propertyType.Equals("partialCharge")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.setCharge(System.Double.Parse(propertyValue)); } else if (propertyType.Equals("hydrogenCount")) { currentAtom.setHydrogenCount(System.Int32.Parse(propertyValue)); } else if (propertyType.Equals("dictRef")) { currentAtom.setProperty("org.openscience.cdk.dict", propertyValue); } else if (propertyType.Equals("atomicNumber")) { currentAtom.AtomicNumber = System.Int32.Parse(propertyValue); } else if (propertyType.Equals("massNumber")) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" currentAtom.MassNumber = (int)(System.Double.Parse(propertyValue)); } else if (propertyType.Equals("spinMultiplicity")) { int unpairedElectrons = System.Int32.Parse(propertyValue) - 1; for (int i = 0; i < unpairedElectrons; i++) { currentMolecule.addElectronContainer(currentChemFile.Builder.newSingleElectron(currentAtom)); } } else if (propertyType.Equals("id")) { //logger.debug("id: ", propertyValue); currentAtom.ID = propertyValue; atomEnumeration[propertyValue] = (System.Int32)numberOfAtoms; } } else if (objectType.Equals("Bond")) { if (propertyType.Equals("atom1")) { bond_a1 = System.Int32.Parse(propertyValue); } else if (propertyType.Equals("atom2")) { bond_a2 = System.Int32.Parse(propertyValue); } else if (propertyType.Equals("id")) { //logger.debug("id: " + propertyValue); bond_id = propertyValue; } else if (propertyType.Equals("order")) { try { bond_order = System.Double.Parse(propertyValue); } catch (System.Exception e) { //logger.error("Cannot convert to double: " + propertyValue); bond_order = 1.0; } } else if (propertyType.Equals("stereo")) { if (propertyValue.Equals("H")) { bond_stereo = CDKConstants.STEREO_BOND_DOWN; } else if (propertyValue.Equals("W")) { bond_stereo = CDKConstants.STEREO_BOND_UP; } } } else if (objectType.Equals("Reaction")) { if (propertyType.Equals("id")) { currentReaction.ID = propertyValue; } } else if (objectType.Equals("SetOfReactions")) { if (propertyType.Equals("id")) { currentSetOfReactions.ID = propertyValue; } } else if (objectType.Equals("Reactant")) { if (propertyType.Equals("id")) { currentMolecule.ID = propertyValue; } } else if (objectType.Equals("Product")) { if (propertyType.Equals("id")) { currentMolecule.ID = propertyValue; } } else if (objectType.Equals("Crystal")) { // set these variables if (currentMolecule is ICrystal) { ICrystal current = (ICrystal)currentMolecule; if (propertyType.Equals("spacegroup")) { //logger.debug("Setting crystal spacegroup to: " + propertyValue); current.SpaceGroup = propertyValue; } else if (propertyType.Equals("z")) { try { //logger.debug("Setting z to: " + propertyValue); current.Z = System.Int32.Parse(propertyValue); } catch (System.FormatException exception) { //logger.error("Error in format of Z value"); } } } else { //logger.warn("Cannot add crystal cell parameters to a non " + "Crystal class!"); } } else if (objectType.Equals("a-axis") || objectType.Equals("b-axis") || objectType.Equals("c-axis")) { // set these variables if (currentMolecule is ICrystal) { //logger.debug("Setting axis (" + objectType + "): " + propertyValue); if (propertyType.Equals("x")) { crystal_axis_x = System.Double.Parse(propertyValue); } else if (propertyType.Equals("y")) { crystal_axis_y = System.Double.Parse(propertyValue); } else if (propertyType.Equals("z")) { crystal_axis_z = System.Double.Parse(propertyValue); } } else { //logger.warn("Cannot add crystal cell parameters to a non " + "Crystal class!"); } } //logger.debug("Object property set..."); }
/// <summary> Produces an AtomContainer without explicit Hs but with H count from one with Hs. /// The new molecule is a deep copy. /// /// </summary> /// <param name="atomContainer">The AtomContainer from which to remove the hydrogens /// </param> /// <returns> The molecule without Hs. /// </returns> /// <cdk.keyword> hydrogen, removal </cdk.keyword> public static IAtomContainer removeHydrogens(IAtomContainer atomContainer) { //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" System.Collections.IDictionary map = new System.Collections.Hashtable(); // maps original atoms to clones. System.Collections.IList remove = new System.Collections.ArrayList(); // lists removed Hs. // Clone atoms except those to be removed. IMolecule mol = atomContainer.Builder.newMolecule(); int count = atomContainer.AtomCount; for (int i = 0; i < count; i++) { // Clone/remove this atom? IAtom atom = atomContainer.getAtomAt(i); if (!atom.Symbol.Equals("H")) { IAtom clonedAtom = null; try { clonedAtom = (IAtom)atom.Clone(); } //UPGRADE_NOTE: Exception 'java.lang.CloneNotSupportedException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'" catch (System.Exception e) { // TODO Auto-generated catch block SupportClass.WriteStackTrace(e, Console.Error); } clonedAtom.setHydrogenCount(0); mol.addAtom(clonedAtom); map[atom] = clonedAtom; } else { remove.Add(atom); // maintain list of removed H. } } // Clone bonds except those involving removed atoms. count = atomContainer.getBondCount(); for (int i = 0; i < count; i++) { // Check bond. //UPGRADE_NOTE: Final was removed from the declaration of 'bond '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" IBond bond = atomContainer.getBondAt(i); IAtom[] atoms = bond.getAtoms(); bool removedBond = false; //UPGRADE_NOTE: Final was removed from the declaration of 'length '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" int length = atoms.Length; for (int k = 0; k < length; k++) { if (remove.Contains(atoms[k])) { removedBond = true; break; } } // Clone/remove this bond? if (!removedBond) // if (!remove.contains(atoms[0]) && !remove.contains(atoms[1])) { IBond clone = null; try { clone = (IBond)atomContainer.getBondAt(i).Clone(); } //UPGRADE_NOTE: Exception 'java.lang.CloneNotSupportedException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'" catch (System.Exception e) { // TODO Auto-generated catch block SupportClass.WriteStackTrace(e, Console.Error); } clone.setAtoms(new IAtom[] { (IAtom)map[atoms[0]], (IAtom)map[atoms[1]] }); mol.addBond(clone); } } // Recompute hydrogen counts of neighbours of removed Hydrogens. //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" for (System.Collections.IEnumerator i = remove.GetEnumerator(); i.MoveNext();) { // Process neighbours. //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" for (System.Collections.IEnumerator n = atomContainer.getConnectedAtomsVector((IAtom)i.Current).GetEnumerator(); n.MoveNext();) { //UPGRADE_NOTE: Final was removed from the declaration of 'neighb '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" IAtom neighb = (IAtom)map[n.Current]; neighb.setHydrogenCount(neighb.getHydrogenCount() + 1); } } mol.Properties = atomContainer.Properties; mol.Flags = atomContainer.Flags; return(mol); }