/// <summary>  Reads a set of vibrations into ChemFrame.
        ///
        /// </summary>
        /// <param name="model">           Description of the Parameter
        /// </param>
        /// <exception cref="IOException"> if an I/O error occurs
        /// </exception>
        //	private void readFrequencies(IChemModel model) throws IOException
        //	{

        /*
         *  FIXME: this is yet to be ported
         *  String line;
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  while ((line != null) && line.startsWith(" Frequencies --")) {
         *  Vector currentVibs = new Vector();
         *  StringReader vibValRead = new StringReader(line.substring(15));
         *  StreamTokenizer token = new StreamTokenizer(vibValRead);
         *  while (token.nextToken() != StreamTokenizer.TT_EOF) {
         *  Vibration vib = new Vibration(Double.toString(token.nval));
         *  currentVibs.addElement(vib);
         *  }
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  for (int i = 0; i < frame.getAtomCount(); ++i) {
         *  line = input.readLine();
         *  StringReader vectorRead = new StringReader(line);
         *  token = new StreamTokenizer(vectorRead);
         *  token.nextToken();
         *  / ignore first token
         *  token.nextToken();
         *  / ignore second token
         *  for (int j = 0; j < currentVibs.size(); ++j) {
         *  double[] v = new double[3];
         *  if (token.nextToken() == StreamTokenizer.TT_NUMBER) {
         *  v[0] = token.nval;
         *  } else {
         *  throw new IOException("Error reading frequency");
         *  }
         *  if (token.nextToken() == StreamTokenizer.TT_NUMBER) {
         *  v[1] = token.nval;
         *  } else {
         *  throw new IOException("Error reading frequency");
         *  }
         *  if (token.nextToken() == StreamTokenizer.TT_NUMBER) {
         *  v[2] = token.nval;
         *  } else {
         *  throw new IOException("Error reading frequency");
         *  }
         *  ((Vibration) currentVibs.elementAt(j)).addAtomVector(v);
         *  }
         *  }
         *  for (int i = 0; i < currentVibs.size(); ++i) {
         *  frame.addVibration((Vibration) currentVibs.elementAt(i));
         *  }
         *  line = input.readLine();
         *  line = input.readLine();
         *  line = input.readLine();
         *  }
         */
        //	}


        /// <summary> Reads NMR nuclear shieldings.
        ///
        /// </summary>
        /// <param name="model">    Description of the Parameter
        /// </param>
        /// <param name="labelLine">Description of the Parameter
        /// </param>
        /// <throws>  CDKException Description of the Exception </throws>
        private void readNMRData(IChemModel model, System.String labelLine)
        {
            IAtomContainer ac = ChemModelManipulator.getAllInOneContainer(model);

            // Determine label for properties
            System.String label;
            if (labelLine.IndexOf("Diamagnetic") >= 0)
            {
                label = "Diamagnetic Magnetic shielding (Isotropic)";
            }
            else if (labelLine.IndexOf("Paramagnetic") >= 0)
            {
                label = "Paramagnetic Magnetic shielding (Isotropic)";
            }
            else
            {
                label = "Magnetic shielding (Isotropic)";
            }
            int atomIndex = 0;

            for (int i = 0; i < atomCount; ++i)
            {
                try
                {
                    System.String line = input.ReadLine().Trim();
                    while (line.IndexOf("Isotropic") < 0)
                    {
                        if (line == null)
                        {
                            return;
                        }
                        line = input.ReadLine().Trim();
                    }
                    SupportClass.Tokenizer st1 = new SupportClass.Tokenizer(line);

                    // Find Isotropic label
                    while (st1.HasMoreTokens())
                    {
                        if (st1.NextToken().Equals("Isotropic"))
                        {
                            break;
                        }
                    }

                    // Find Isotropic value
                    while (st1.HasMoreTokens())
                    {
                        if (st1.NextToken().Equals("="))
                        {
                            break;
                        }
                    }
                    double shielding = System.Double.Parse(st1.NextToken());
                    //logger.info("Type of shielding: " + label);
                    ac.getAtomAt(atomIndex).setProperty(CDKConstants.ISOTROPIC_SHIELDING, (System.Object)shielding);
                    ++atomIndex;
                }
                catch (System.Exception exc)
                {
                    //logger.debug("failed to read line from gaussian98 file where I expected one.");
                }
            }
        }
Beispiel #2
0
        private static void ProcessChemModel(IChemModel chemModel, ISettings settings, FileUsage usage,
                                             MoleculeLoadingResults results, MoleculeProcessingProgress progress,
                                             float sectionSz)
        {
            //if (ChemModelManipulator.getAllInOneContainer(chemModel).getBondCount() == 0)
            //{
            //    return;
            //}

            // check for coordinates
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))//
            {
                results.Num2DCoords++;
            }
            //    usage == FileUsage.TwoD)
            //{
            //    throw new UserLevelException("File has no 2D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))// &&
            {
                results.Num3DCoords++;
            }
            //    usage == FileUsage.ThreeD)
            //{
            //    throw new UserLevelException("File has no 3D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}

            ElementPTFactory elements = ElementPTFactory.Instance;

            // calc item sz
            int numItems = 0;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    numItems += chemModel.SetOfMolecules.Molecules[mol].Atoms.Length;
                    //numItems += chemModel.SetOfMolecules.Molecules[mol].Bonds.Length;
                }
            }
            float itemSz = sectionSz / (float)numItems;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    IMolecule molecule = chemModel.SetOfMolecules.Molecules[mol];
                    results.NumAtoms += molecule.Atoms.Length;
                    results.NumBonds += molecule.Bonds.Length;
                    foreach (IAtom atom in molecule.Atoms)
                    {
                        PeriodicTableElement pe = elements.getElement(atom.Symbol);
                        if (pe != null)
                        {
                            atom.AtomicNumber = pe.AtomicNumber;
                            atom.Properties["PeriodicTableElement"] = pe;
                            atom.Properties["Period"] = int.Parse(pe.Period);
                        }
                        else
                        {
                            progress.Log(string.Format("Failed to find periodic element: {0}", atom.Symbol), LogItem.ItemLevel.Failure);
                        }
                        progress.UpdateProgress(itemSz);
                    }
                    progress.Log(string.Format("Processed {0} atoms", molecule.Atoms.Length), LogItem.ItemLevel.Info);
                }
            }
            progress.Log("Processed Model", LogItem.ItemLevel.Success);
        }