public bool AddImplicitHydrogens(IAtomContainer molecule) { try { var builder = molecule.getBuilder(); var matcher = CDKAtomTypeMatcher.getInstance(builder); foreach (var atom in molecule.atoms().ToWindowsEnumerable<IAtom>()) { var type = matcher.findMatchingAtomType(molecule, atom); AtomTypeManipulator.configure(atom, type); } var hAdder = CDKHydrogenAdder.getInstance(builder); hAdder.addImplicitHydrogens(molecule); AtomContainerManipulator.convertImplicitToExplicitHydrogens(molecule); } //there is a bug in cdk?? error happens when there is a S or Ti in the molecule catch (IllegalArgumentException) { return false; } return true; }
/// <summary> Removes all external aliphatic chains by chopping them off from the /// ends /// /// </summary> /// <param name="ac"> The AtomContainer to work with /// </param> /// <exception cref="CDKException"> An exception thrown if something goes wrong or if the timeout limit is reached /// </exception> private void removeAliphatic(IAtomContainer ac) { bool removedSomething; IAtom atom = null; do { removedSomething = false; //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' 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_javautilEnumerationhasMoreElements'" for (System.Collections.IEnumerator e = ac.atoms(); e.MoveNext();) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' 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_javautilEnumerationnextElement'" atom = (IAtom)e.Current; if (ac.getBondCount(atom) == 1) { ac.removeAtomAndConnectedElectronContainers(atom); removedSomething = true; } } }while (removedSomething); }
public static IMolecularFormula GetMolecularFormula(IAtomContainer atomContainer) { var formula = new MolecularFormula(); var charge = 0; var hydrogen = new Atom("H"); foreach (var iAtom in atomContainer.atoms().ToWindowsEnumerable<IAtom>()) { formula.addIsotope(iAtom); charge += iAtom.getFormalCharge().intValue(); var implicitHydrogenCount = iAtom.getImplicitHydrogenCount(); var implicitHydrogenCountValue = implicitHydrogenCount != null ? implicitHydrogenCount.intValue() : (int?) null; if (implicitHydrogenCountValue.HasValue && implicitHydrogenCountValue.Value > 0) { formula.addIsotope(hydrogen, implicitHydrogenCountValue.Value); } } formula.setCharge(new Integer(charge)); return formula; }
/// <summary> Calculates the center of mass for the <code>Atom</code>s in the /// AtomContainer for the 2D coordinates. /// See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets /// /// </summary> /// <param name="ac"> AtomContainer for which the center of mass is calculated /// </param> /// <returns> Description of the Return Value /// </returns> /// <cdk.keyword> center of mass </cdk.keyword> /// <cdk.dictref> blue-obelisk:calculate3DCenterOfMass </cdk.dictref> public static Point3d get3DCentreOfMass(IAtomContainer ac) { double x = 0.0; double y = 0.0; double z = 0.0; double totalmass = 0.0; System.Collections.IEnumerator atoms = ac.atoms(); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' 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_javautilEnumerationhasMoreElements'" while (atoms.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' 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_javautilEnumerationnextElement'" IAtom a = (IAtom)atoms.Current; double mass = a.getExactMass(); totalmass += mass; x += mass * a.X3d; y += mass * a.Y3d; z += mass * a.Z3d; } return new Point3d(x / totalmass, y / totalmass, z / totalmass); }
/// <summary> Removes all external aliphatic chains by chopping them off from the /// ends /// /// </summary> /// <param name="ac"> The AtomContainer to work with /// </param> /// <exception cref="CDKException"> An exception thrown if something goes wrong or if the timeout limit is reached /// </exception> private void removeAliphatic(IAtomContainer ac) { bool removedSomething; IAtom atom = null; do { removedSomething = false; //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' 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_javautilEnumerationhasMoreElements'" for (System.Collections.IEnumerator e = ac.atoms(); e.MoveNext(); ) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' 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_javautilEnumerationnextElement'" atom = (IAtom)e.Current; if (ac.getBondCount(atom) == 1) { ac.removeAtomAndConnectedElectronContainers(atom); removedSomething = true; } } } while (removedSomething); }