/// <summary> /// </summary> /// <param name="set">The collection of IAtomContainer objects</param> /// <returns>The summed formal charges of all atoms in this set.</returns> public static double GetTotalFormalCharge(IChemObjectSet <IAtomContainer> set) { int charge = 0; for (int i = 0; i < set.Count; i++) { int thisCharge = AtomContainerManipulator.GetTotalFormalCharge(set[i]); double stoich = set.GetMultiplier(i).Value; charge += (int)(stoich * thisCharge); } return(charge); }
public override void Write(IChemObject arg0) { CustomizeJob(); if (arg0 is IAtomContainer) { try { IAtomContainer container = (IAtomContainer)arg0; writer.Write(mopacCommands.Setting); int formalCharge = AtomContainerManipulator.GetTotalFormalCharge(container); if (formalCharge != 0) { writer.Write(" CHARGE=" + formalCharge); } writer.Write('\n'); //if (container.GetProperty("Names") != null) writer.Write(container.GetProperty("Names").ToString()); writer.Write('\n'); writer.Write(Title); writer.Write('\n'); for (int i = 0; i < container.Atoms.Count; i++) { IAtom atom = container.Atoms[i]; if (atom.Point3D != null) { Vector3 point = atom.Point3D.Value; WriteAtom(atom, point.X, point.Y, point.Z, optimize.IsSet ? 1 : 0); } else if (atom.Point2D != null) { Vector2 point = atom.Point2D.Value; WriteAtom(atom, point.X, point.Y, 0, optimize.IsSet ? 1 : 0); } else { WriteAtom(atom, 0, 0, 0, 1); } } writer.Write("0"); writer.Write('\n'); } catch (IOException ioException) { Trace.TraceError(ioException.Message); throw new CDKException(ioException.Message, ioException); } } else { throw new CDKException("Unsupported object!\t" + arg0.GetType().Name); } }