// returns an equivalent replica of the molecule public virtual Molecule Clone() { Molecule mol = new Molecule(); for (int n = 1; n <= NumAtoms(); n++) { Atom a = atoms[n - 1]; int num = mol.AddAtom(a.Element, a.X, a.Y, a.Charge, a.Unpaired); mol.SetAtomHExplicit(num, AtomHExplicit(n)); } for (int n = 1; n <= NumBonds(); n++) { Bond b = bonds[n - 1]; mol.AddBond(b.From, b.To, b.Order, b.Type); } return mol; }
public static Molecule ReadNative(System.IO.StreamReader in_Renamed) { Molecule mol = new Molecule(); //UPGRADE_NOTE: Final was removed from the declaration of 'GENERIC_ERROR '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.String GENERIC_ERROR = "Invalid SketchEl file."; try { System.String line = in_Renamed.ReadLine(); if (!line.StartsWith("SketchEl!")) throw new System.IO.IOException("Not a SketchEl file."); int p1 = line.IndexOf('('), p2 = line.IndexOf(','), p3 = line.IndexOf(')'); if (p1 == 0 || p2 == 0 || p3 == 0) throw new System.IO.IOException(GENERIC_ERROR); int numAtoms = System.Int32.Parse(line.Substring(p1 + 1, (p2) - (p1 + 1)).Trim()); int numBonds = System.Int32.Parse(line.Substring(p2 + 1, (p3) - (p2 + 1)).Trim()); for (int n = 0; n < numAtoms; n++) { line = in_Renamed.ReadLine(); // TODO: verify java's split method syntax: "[\\=\\,\\;]" System.String[] bits = line.Split('=', ',', ';'); if (bits.Length < 5) throw new System.IO.IOException(GENERIC_ERROR); int num = mol.AddAtom(bits[0], System.Double.Parse(bits[1].Trim()), System.Double.Parse(bits[2].Trim()), System.Int32.Parse(bits[3].Trim()), System.Int32.Parse(bits[4].Trim())); if (bits.Length >= 6 && bits[5].Length > 0 && bits[5][0] == 'e') mol.SetAtomHExplicit(num, System.Int32.Parse(bits[5].Substring(1))); } for (int n = 0; n < numBonds; n++) { line = in_Renamed.ReadLine(); System.String[] bits = line.Split('-', '=', ','); // "[\\-\\=\\,]"); if (bits.Length < 4) throw new System.IO.IOException(GENERIC_ERROR); mol.AddBond(System.Int32.Parse(bits[0].Trim()), System.Int32.Parse(bits[1].Trim()), System.Int32.Parse(bits[2].Trim()), System.Int32.Parse(bits[3].Trim())); } line = in_Renamed.ReadLine(); if (String.CompareOrdinal(line, "!End") != 0) throw new System.IO.IOException(GENERIC_ERROR); } catch (System.Exception) { throw new System.IO.IOException(GENERIC_ERROR); } return mol; }