Esempio n. 1
0
        private static void ParseBondBlock(StreamReader reader, ref Molecule mol)
        {
            //One bond per line in format
            // 111222tttsssxxxrrrccc first atom # second atom # bond type bond stereo
            //Generally there will be spaces otherwise this f***s up
            string line = string.Empty;
            for (int i = 0; i < mol.NumberOfBonds; i++)
            {
                string[] delim = { " " };
                string[] parts = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries);
                //The first two pars are atoms 1 and 2
                int atom1Key, atom2Key;
                bool result = int.TryParse(parts[0], out atom1Key);
                if (!result)
                    Console.WriteLine("Could not get the first atom number");
                result = int.TryParse(parts[1], out atom2Key);
                if (!result)
                    Console.WriteLine("Could not get the second atom number");

                int bondOrder;
                result = int.TryParse(parts[2], out bondOrder);
                if (!result)
                    Console.WriteLine("Could not get the bond order for "+atom1Key+"'s connection to"+atom2Key);

                //Now we build the bond
                try
                {
                    Bond bondToAdd = new Bond(mol.Atoms[atom1Key], mol.Atoms[atom2Key], bondOrder);
                    mol.Bonds.Add(bondToAdd);

                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("The keys found were out of range 1:" + atom1Key + " 2:" + atom2Key + " atom count" +
                        mol.Atoms.Count);
                }

            }
        }
Esempio n. 2
0
 public object Clone()
 {
     Bond bondCopy = new Bond((Node)node1.Clone(), (Node)node2.Clone(), this.bondOrder);
     return bondCopy;
 }