Пример #1
0
 public void TestSetMoleculeSet_IAtomContainerSet()
 {
     IChemModel chemModel = (IChemModel)NewChemObject();
     IChemObjectSet<IAtomContainer> crystal = chemModel.Builder.NewAtomContainerSet();
     chemModel.MoleculeSet = crystal;
     Assert.AreEqual(crystal, chemModel.MoleculeSet);
 }
Пример #2
0
        public void TestTaxols()
        {
            var filename = "NCDK.Data.ASN.PubChem.taxols.xml";

            Trace.TraceInformation("Testing: " + filename);

            int           modelCount = 0;
            IChemSequence set;

            using (var ins = ResourceLoader.GetAsStream(filename))
                using (var sr = new StreamReader(ins))
                    using (var reader = new EnumerablePCSubstancesXMLReader(sr, ChemObjectBuilder.Instance))
                    {
                        set = ChemObjectBuilder.Instance.NewChemSequence();
                        foreach (var obj in reader)
                        {
                            Assert.IsNotNull(obj);
                            Assert.IsTrue(obj is IChemModel);
                            set.Add((IChemModel)obj);
                            modelCount++;
                        }
                    }

            Assert.AreEqual(77, modelCount);
            IChemModel first = set[0];

            Assert.AreEqual(63, ChemModelManipulator.GetAtomCount(first));
            Assert.AreEqual(69, ChemModelManipulator.GetBondCount(first));
        }
Пример #3
0
 /// <summary> Takes an object which subclasses IChemObject, e.g.Molecule, and will read
 /// this (from file, database, internet etc). If the specific implementation
 /// does not support a specific IChemObject it will throw an Exception.
 ///
 /// </summary>
 /// <param name="object">                             The object that subclasses
 /// IChemObject
 /// </param>
 /// <returns>                                     The IChemObject read
 /// </returns>
 /// <exception cref="CDKException">
 /// </exception>
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IReaction)
     {
         return((IChemObject)readReaction(object_Renamed.Builder));
     }
     else if (object_Renamed is IChemModel)
     {
         IChemModel      model       = object_Renamed.Builder.newChemModel();
         ISetOfReactions reactionSet = object_Renamed.Builder.newSetOfReactions();
         reactionSet.addReaction(readReaction(object_Renamed.Builder));
         model.SetOfReactions = reactionSet;
         return(model);
     }
     else if (object_Renamed is IChemFile)
     {
         IChemFile     chemFile = object_Renamed.Builder.newChemFile();
         IChemSequence sequence = object_Renamed.Builder.newChemSequence();
         sequence.addChemModel((IChemModel)read(object_Renamed.Builder.newChemModel()));
         chemFile.addChemSequence(sequence);
         return(chemFile);
     }
     else
     {
         throw new CDKException("Only supported are Reaction and ChemModel, and not " + object_Renamed.GetType().FullName + ".");
     }
 }
Пример #4
0
        /// <summary>
        /// Adds an chemModel to this container.
        /// </summary>
        /// <param name="chemModel">The chemModel to be added to this container</param>
        public void Add(IChemModel chemModel)
        {
            chemModels.Add(chemModel);

            chemModel.Listeners.Add(this);
            NotifyChanged();
        }
Пример #5
0
 public void SetUp()
 {
     molecule1  = builder.NewAtomContainer();
     atomInMol1 = builder.NewAtom("Cl");
     molecule1.Atoms.Add(atomInMol1);
     molecule1.Atoms.Add(builder.NewAtom("Cl"));
     bondInMol1 = builder.NewBond(atomInMol1, molecule1.Atoms[1]);
     molecule1.Bonds.Add(bondInMol1);
     molecule2  = builder.NewAtomContainer();
     atomInMol2 = builder.NewAtom("O");
     atomInMol2.ImplicitHydrogenCount = 2;
     molecule2.Atoms.Add(atomInMol2);
     moleculeSet = builder.NewChemObjectSet <IAtomContainer>();
     moleculeSet.Add(molecule1);
     moleculeSet.Add(molecule2);
     reaction = builder.NewReaction();
     reaction.Reactants.Add(molecule1);
     reaction.Products.Add(molecule2);
     reactionSet = builder.NewReactionSet();
     reactionSet.Add(reaction);
     chemModel             = builder.NewChemModel();
     chemModel.MoleculeSet = moleculeSet;
     chemModel.ReactionSet = reactionSet;
     chemSequence1         = builder.NewChemSequence();
     chemSequence1.Add(chemModel);
     chemSequence2 = builder.NewChemSequence();
     chemFile      = builder.NewChemFile();
     chemFile.Add(chemSequence1);
     chemFile.Add(chemSequence2);
 }
Пример #6
0
 /// <summary>Creates from a PDB File a BioPolymer.</summary>
 private void ReadBioPolymer(string biopolymerFile)
 {
     try
     {
         // Read PDB file
         var fileReader = new StreamReader(biopolymerFile);
         ISimpleChemObjectReader reader = new ReaderFactory().CreateReader(fileReader);
         IChemFile chemFile             = (IChemFile)reader.Read((IChemObject) new ChemFile());
         // Get molecule from ChemFile
         IChemSequence chemSequence   = chemFile[0];
         IChemModel    chemModel      = chemSequence[0];
         var           setOfMolecules = chemModel.MoleculeSet;
         Protein = (IBioPolymer)setOfMolecules[0];
     }
     catch (Exception exc)
     {
         if (exc is IOException || exc is CDKException)
         {
             Trace.TraceError("Could not read BioPolymer from file>" + biopolymerFile + " due to: " + exc.Message);
             Debug.WriteLine(exc);
         }
         else
         {
             throw;
         }
     }
 }
Пример #7
0
 public override void StartDocument()
 {
     ChemFile       = CDK.Builder.NewChemFile();
     chemSequence   = CDK.Builder.NewChemSequence();
     chemModel      = CDK.Builder.NewChemModel();
     setOfMolecules = CDK.Builder.NewChemObjectSet <IAtomContainer>();
 }
Пример #8
0
        public ValidationReport ValidateChemModel(IChemModel subject)
        {
            Trace.TraceInformation($"Validating {nameof(IChemModel)}");
            var report = new ValidationReport();

            // apply validators
            foreach (var test in validators.Values)
            {
                report.Add(test.ValidateChemModel(subject));
            }
            // traverse into super class
            report.Add(ValidateChemObject(subject));
            // traverse into hierarchy
            ICrystal crystal = subject.Crystal;

            if (crystal != null)
            {
                report.Add(ValidateCrystal(crystal));
            }
            IReactionSet reactionSet = subject.ReactionSet;

            if (reactionSet != null)
            {
                report.Add(ValidateReactionSet(reactionSet));
            }
            var moleculeSet = subject.MoleculeSet;

            if (moleculeSet != null)
            {
                report.Add(ValidateMoleculeSet(moleculeSet));
            }
            return(report);
        }
Пример #9
0
 public void TestSetCrystal_ICrystal()
 {
     IChemModel chemModel = (IChemModel)NewChemObject();
     ICrystal crystal = chemModel.Builder.NewCrystal();
     chemModel.Crystal = crystal;
     Assert.AreEqual(crystal, chemModel.Crystal);
 }
Пример #10
0
        public static IEnumerable <string> GetAllIDs(IChemModel chemModel)
        {
            if (chemModel.Id != null)
            {
                yield return(chemModel.Id);
            }
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                foreach (var e in AtomContainerManipulator.GetAllIDs(crystal))
                {
                    yield return(e);
                }
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                foreach (var e in MoleculeSetManipulator.GetAllIDs(moleculeSet))
                {
                    yield return(e);
                }
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                foreach (var e in ReactionSetManipulator.GetAllIDs(reactionSet))
                {
                    yield return(e);
                }
            }
            yield break;
        }
Пример #11
0
        public static void removeAtomAndConnectedElectronContainers(IChemModel chemModel, IAtom atom)
        {
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.contains(atom))
                {
                    crystal.removeAtomAndConnectedElectronContainers(atom);
                }
                return;
            }
            ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;

            if (moleculeSet != null)
            {
                SetOfMoleculesManipulator.removeAtomAndConnectedElectronContainers(moleculeSet, atom);
            }
            ISetOfReactions reactionSet = chemModel.SetOfReactions;

            if (reactionSet != null)
            {
                SetOfReactionsManipulator.removeAtomAndConnectedElectronContainers(reactionSet, atom);
            }
        }
Пример #12
0
        private IAtomContainer ReadCMLMolecule(string filename)
        {
            IAtomContainer mol = null;

            Debug.WriteLine($"Filename: {filename}");
            var ins    = ResourceLoader.GetAsStream(filename);
            var reader = new CMLReader(ins);

            IChemFile file = (IChemFile)reader.Read(builder.NewChemFile());

            Assert.IsNotNull(file);
            Assert.AreEqual(1, file.Count);
            IChemSequence sequence = file[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(1, sequence.Count);
            IChemModel chemModel = sequence[0];

            Assert.IsNotNull(chemModel);
            var moleculeSet = chemModel.MoleculeSet;

            Assert.IsNotNull(moleculeSet);
            Assert.AreEqual(1, moleculeSet.Count);
            mol = moleculeSet[0];
            Assert.IsNotNull(mol);

            return(mol);
        }
Пример #13
0
        /// <summary>
        /// Adds a new Molecule to the MoleculeSet inside a given ChemModel.
        /// Creates a MoleculeSet if none is contained.
        /// </summary>
        /// <param name="chemModel">The ChemModel object.</param>
        /// <returns>The created Molecule object.</returns>
        public static IAtomContainer CreateNewMolecule(IChemModel chemModel)
        {
            // Add a new molecule either the set of molecules
            IAtomContainer molecule = chemModel.Builder.NewAtomContainer();

            if (chemModel.MoleculeSet != null)
            {
                IChemObjectSet <IAtomContainer> moleculeSet = chemModel.MoleculeSet;
                for (int i = 0; i < moleculeSet.Count; i++)
                {
                    if (moleculeSet[i].Atoms.Count == 0)
                    {
                        moleculeSet.RemoveAt(i);
                        i--;
                    }
                }
                moleculeSet.Add(molecule);
            }
            else
            {
                var moleculeSet = chemModel.Builder.NewAtomContainerSet();
                moleculeSet.Add(molecule);
                chemModel.MoleculeSet = moleculeSet;
            }
            return(molecule);
        }
Пример #14
0
        /// <summary>
        /// Remove an Atom and the connected ElectronContainers from all AtomContainers
        /// inside an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <param name="atom">The Atom object to remove.</param>
        public static void RemoveAtomAndConnectedElectronContainers(IChemModel chemModel, IAtom atom)
        {
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.Contains(atom))
                {
                    crystal.RemoveAtom(atom);
                }
                return;
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                MoleculeSetManipulator.RemoveAtomAndConnectedElectronContainers(moleculeSet, atom);
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                ReactionSetManipulator.RemoveAtomAndConnectedElectronContainers(reactionSet, atom);
            }
        }
Пример #15
0
 /// <summary> Takes an object which subclasses IChemObject, e.g.Molecule, and will read
 /// this from from the Reader. If the specific implementation
 /// does not support a specific IChemObject it will throw an Exception.
 ///
 /// </summary>
 /// <param name="object">The object that subclasses IChemObject
 /// </param>
 /// <returns>        The IChemObject read
 /// </returns>
 /// <exception cref="CDKException">
 /// </exception>
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemFile)
     {
         IChemFile       file        = (IChemFile)object_Renamed;
         IChemSequence   sequence    = file.Builder.newChemSequence();
         IChemModel      model       = file.Builder.newChemModel();
         ISetOfMolecules moleculeSet = file.Builder.newSetOfMolecules();
         moleculeSet.addMolecule(readMolecule(model.Builder.newMolecule()));
         model.SetOfMolecules = moleculeSet;
         sequence.addChemModel(model);
         file.addChemSequence(sequence);
         return(file);
     }
     else if (object_Renamed is IChemModel)
     {
         IChemModel      model       = (IChemModel)object_Renamed;
         ISetOfMolecules moleculeSet = model.Builder.newSetOfMolecules();
         moleculeSet.addMolecule(readMolecule(model.Builder.newMolecule()));
         model.SetOfMolecules = moleculeSet;
         return(model);
     }
     else
     {
         throw new CDKException("Only supported is ChemModel, and not " + object_Renamed.GetType().FullName + ".");
     }
 }
Пример #16
0
        private CMLList CDKChemModelToCMLList(IChemModel model, bool setIDs)
        {
            var cmlList = new CMLList {
                Convention = "cdk:model"
            };

            if (useCMLIDs && setIDs)
            {
                IDCreator.CreateIDs(model);
            }
            if (!string.IsNullOrEmpty(model.Id))
            {
                cmlList.Id = model.Id;
            }

            if (model.Crystal != null)
            {
                cmlList.Add(CDKCrystalToCMLMolecule(model.Crystal, false));
            }
            if (model.ReactionSet != null)
            {
                cmlList.Add(CDKReactionSetToCMLReactionList(model.ReactionSet, false));
            }
            if (model.MoleculeSet != null)
            {
                cmlList.Add(CDKAtomContainerSetToCMLList(model.MoleculeSet, false));
            }

            return(cmlList);
        }
Пример #17
0
 public void SetUp()
 {
     molecule1  = new AtomContainer();
     atomInMol1 = new Atom("Cl")
     {
         Charge                = -1.0,
         FormalCharge          = -1,
         ImplicitHydrogenCount = 1
     };
     molecule1.Atoms.Add(atomInMol1);
     molecule1.Atoms.Add(new Atom("Cl"));
     bondInMol1 = new Bond(atomInMol1, molecule1.Atoms[1]);
     molecule1.Bonds.Add(bondInMol1);
     molecule2  = new AtomContainer();
     atomInMol2 = new Atom("O")
     {
         ImplicitHydrogenCount = 2
     };
     molecule2.Atoms.Add(atomInMol2);
     moleculeSet = ChemObjectBuilder.Instance.NewAtomContainerSet();
     moleculeSet.Add(molecule1);
     moleculeSet.Add(molecule2);
     reaction = new Reaction();
     reaction.Reactants.Add(molecule1);
     reaction.Products.Add(molecule2);
     reactionSet = new ReactionSet
     {
         reaction
     };
     chemModel = new ChemModel
     {
         MoleculeSet = moleculeSet,
         ReactionSet = reactionSet
     };
 }
Пример #18
0
        /// <summary>
        /// Calculate the bounding rectangle for a chem model.
        /// </summary>
        /// <param name="chemModel">the chem model to use</param>
        /// <returns>the bounding rectangle of the chem model</returns>
        public static Rect CalculateBounds(IChemModel chemModel)
        {
            var moleculeSet = chemModel.MoleculeSet;
            var reactionSet = chemModel.ReactionSet;
            var totalBounds = Rect.Empty;

            if (moleculeSet != null)
            {
                totalBounds = CalculateBounds(moleculeSet);
            }
            if (reactionSet != null)
            {
                if (totalBounds.IsEmpty)
                {
                    totalBounds = CalculateBounds(moleculeSet);
                }
                else
                {
                    totalBounds = Rect.Union(totalBounds, CalculateBounds(reactionSet));
                }
            }
            if (totalBounds.IsEmpty)
            {
                totalBounds = new Rect();
            }
            return(totalBounds);
        }
Пример #19
0
        public void TestRDFModel()
        {
            var filename = "NCDK.Data.MDL.qsar-reaction-test.rdf";

            Trace.TraceInformation("Testing: " + filename);
            var          ins       = ResourceLoader.GetAsStream(filename);
            MDLRXNReader reader    = new MDLRXNReader(ins);
            IChemModel   chemModel = (IChemModel)reader.Read(builder.NewChemModel());

            reader.Close();
            Assert.IsNotNull(chemModel);

            Assert.AreEqual(2, chemModel.ReactionSet.Count);
            Assert.AreEqual(2, chemModel.ReactionSet[0].Reactants.Count);
            Assert.AreEqual(3, chemModel.ReactionSet[0].Reactants[0]
                            .Atoms.Count);
            Assert.AreEqual(2, chemModel.ReactionSet[0].Reactants[1]
                            .Atoms.Count);
            Assert.AreEqual(2, chemModel.ReactionSet[0].Products.Count);
            Assert.AreEqual(2, chemModel.ReactionSet[0].Products[0]
                            .Atoms.Count);
            Assert.AreEqual(2, chemModel.ReactionSet[0].Products[1]
                            .Atoms.Count);

            Assert.AreEqual(1, chemModel.ReactionSet[1].Reactants.Count);
            Assert.AreEqual(3, chemModel.ReactionSet[1].Reactants[0]
                            .Atoms.Count);
            Assert.AreEqual(1, chemModel.ReactionSet[1].Products.Count);
            Assert.AreEqual(2, chemModel.ReactionSet[1].Products[0]
                            .Atoms.Count);
        }
Пример #20
0
        public static IChemModel RoundTripChemModel(Convertor convertor, IChemModel model)
        {
            string cmlString = "<!-- failed -->";
            var    cmlDOM    = convertor.CDKChemModelToCMLList(model);

            cmlString = cmlDOM.ToString();

            Debug.WriteLine("CML string: ", cmlString);
            IChemFile file;

            using (var reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlString))))
            {
                file = (IChemFile)reader.Read(model.Builder.NewChemFile());
            }
            Assert.IsNotNull(file);
            Assert.AreEqual(1, file.Count);
            IChemSequence sequence = file[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(1, sequence.Count);
            IChemModel chemModel = sequence[0];

            Assert.IsNotNull(chemModel);

            return(chemModel);
        }
Пример #21
0
        /// <summary>
        /// Convert a Molecule to CML and back to a Molecule again.
        /// Given that CML reading is working, the problem is with the CMLWriter.
        /// </summary>
        /// <param name="convertor"></param>
        /// <param name="mol"></param>
        /// <returns></returns>
        /// <seealso cref="CMLFragmentsTest"/>
        public static IAtomContainer RoundTripMolecule(Convertor convertor, IAtomContainer mol)
        {
            string cmlString = "<!-- failed -->";
            var    cmlDOM    = convertor.CDKAtomContainerToCMLMolecule(mol);

            cmlString = cmlDOM.ToString();

            Debug.WriteLine("CML string: ", cmlString);
            IChemFile file;

            using (var reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlString))))
            {
                file = (IChemFile)reader.Read(builder.NewChemFile());
            }
            Assert.IsNotNull(file);
            Assert.AreEqual(1, file.Count);
            IChemSequence sequence = file[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(1, sequence.Count);
            IChemModel chemModel = sequence[0];

            Assert.IsNotNull(chemModel);
            var moleculeSet = chemModel.MoleculeSet;

            Assert.IsNotNull(moleculeSet);
            Assert.AreEqual(1, moleculeSet.Count);
            var roundTrippedMol = moleculeSet[0];

            Assert.IsNotNull(roundTrippedMol);

            return(roundTrippedMol);
        }
Пример #22
0
        public static IReaction RoundTripReaction(Convertor convertor, IReaction reaction)
        {
            string cmlString = "<!-- failed -->";
            var    cmlDOM    = convertor.CDKReactionToCMLReaction(reaction);

            cmlString = cmlDOM.ToString();

            IReaction roundTrippedReaction = null;

            Debug.WriteLine("CML string: ", cmlString);
            CMLReader reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlString)));

            IChemFile file = (IChemFile)reader.Read(builder.NewChemFile());

            reader.Close();
            Assert.IsNotNull(file);
            Assert.AreEqual(1, file.Count);
            IChemSequence sequence = file[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(1, sequence.Count);
            IChemModel chemModel = sequence[0];

            Assert.IsNotNull(chemModel);
            IReactionSet reactionSet = chemModel.ReactionSet;

            Assert.IsNotNull(reactionSet);
            Assert.AreEqual(1, reactionSet.Count);
            roundTrippedReaction = reactionSet[0];
            Assert.IsNotNull(roundTrippedReaction);

            return(roundTrippedReaction);
        }
Пример #23
0
 /// <summary>
 /// Takes an object which subclasses IChemObject, e.g.Molecule, and will read
 /// this (from file, database, Internet etc). If the specific implementation
 /// does not support a specific IChemObject it will throw an Exception.
 /// </summary>
 /// <param name="obj">The object that subclasses <see cref="IChemObject"/></param>
 /// <returns>The <see cref="IChemObject"/> read</returns>
 /// <exception cref="CDKException"></exception>
 public override T Read <T>(T obj)
 {
     if (obj is IReaction)
     {
         return((T)ReadReaction(obj.Builder));
     }
     else if (obj is IReactionSet)
     {
         IReactionSet reactionSet = obj.Builder.NewReactionSet();
         reactionSet.Add(ReadReaction(obj.Builder));
         return((T)reactionSet);
     }
     else if (obj is IChemModel)
     {
         IChemModel   model       = obj.Builder.NewChemModel();
         IReactionSet reactionSet = obj.Builder.NewReactionSet();
         reactionSet.Add(ReadReaction(obj.Builder));
         model.ReactionSet = reactionSet;
         return((T)model);
     }
     else if (obj is IChemFile)
     {
         IChemFile     chemFile = obj.Builder.NewChemFile();
         IChemSequence sequence = obj.Builder.NewChemSequence();
         sequence.Add((IChemModel)Read(obj.Builder.NewChemModel()));
         chemFile.Add(sequence);
         return((T)chemFile);
     }
     else
     {
         throw new CDKException($"Only supported are Reaction and ChemModel, and not {obj.GetType().Name}.");
     }
 }
Пример #24
0
        /// <summary>
        /// This badly named methods tries to determine which AtomContainer in the
        /// ChemModel is best suited to contain added Atom's and Bond's.
        /// </summary>
        public static IAtomContainer GetRelevantAtomContainer(IChemModel chemModel, IAtom atom)
        {
            IAtomContainer result = null;

            if (chemModel.MoleculeSet != null)
            {
                var moleculeSet = chemModel.MoleculeSet;
                result = MoleculeSetManipulator.GetRelevantAtomContainer(moleculeSet, atom);
                if (result != null)
                {
                    return(result);
                }
            }
            if (chemModel.ReactionSet != null)
            {
                var reactionSet = chemModel.ReactionSet;
                return(ReactionSetManipulator.GetRelevantAtomContainer(reactionSet, atom));
            }
            if (chemModel.Crystal != null && chemModel.Crystal.Contains(atom))
            {
                return(chemModel.Crystal);
            }
            if (chemModel.RingSet != null)
            {
                return(AtomContainerSetManipulator.GetRelevantAtomContainer(chemModel.RingSet, atom));
            }
            throw new ArgumentException("The provided atom is not part of this IChemModel.");
        }
Пример #25
0
        public static void removeElectronContainer(IChemModel chemModel, IElectronContainer electrons)
        {
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.contains(electrons))
                {
                    crystal.removeElectronContainer(electrons);
                }
                return;
            }
            ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;

            if (moleculeSet != null)
            {
                SetOfMoleculesManipulator.removeElectronContainer(moleculeSet, electrons);
            }
            ISetOfReactions reactionSet = chemModel.SetOfReactions;

            if (reactionSet != null)
            {
                SetOfReactionsManipulator.removeElectronContainer(reactionSet, electrons);
            }
        }
Пример #26
0
        /// <summary>
        /// Remove an ElectronContainer from all AtomContainers
        /// inside an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <param name="electrons">The ElectronContainer to remove.</param>
        public static void RemoveElectronContainer(IChemModel chemModel, IElectronContainer electrons)
        {
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.Contains(electrons))
                {
                    crystal.Remove(electrons);
                }
                return;
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                MoleculeSetManipulator.RemoveElectronContainer(moleculeSet, electrons);
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                ReactionSetManipulator.RemoveElectronContainer(reactionSet, electrons);
            }
        }
Пример #27
0
 public void TestSetRingSet_IRingSet()
 {
     IChemModel chemModel = (IChemModel)NewChemObject();
     IRingSet crystal = chemModel.Builder.NewRingSet();
     chemModel.RingSet = crystal;
     Assert.AreEqual(crystal, chemModel.RingSet);
 }
Пример #28
0
        public bool Remove(IChemModel chemModel)
        {
            var ret = chemModels.Remove(chemModel);

            chemModel.Listeners.Add(this);
            NotifyChanged();
            return(ret);
        }
Пример #29
0
        /// <summary>
        /// Create a new ChemModel containing an IAtomContainer. It will create an
        /// <see cref="IAtomContainer"/> from the passed IAtomContainer when needed, which may cause
        /// information loss.
        /// </summary>
        /// <param name="atomContainer">The AtomContainer to have inside the ChemModel.</param>
        /// <returns>The new IChemModel object.</returns>
        public static IChemModel NewChemModel(IAtomContainer atomContainer)
        {
            IChemModel model = atomContainer.Builder.NewChemModel();
            IChemObjectSet <IAtomContainer> moleculeSet = model.Builder.NewAtomContainerSet();

            moleculeSet.Add(atomContainer);
            model.MoleculeSet = moleculeSet;
            return(model);
        }
Пример #30
0
        // procedures required by CDOInterface

        /// <summary> Procedure required by the CDOInterface. This function is only
        /// supposed to be called by the JCFL library
        /// </summary>
        public virtual void startDocument()
        {
            //logger.info("New CDO Object");
            currentChemSequence   = currentChemFile.Builder.newChemSequence();
            currentChemModel      = currentChemFile.Builder.newChemModel();
            currentSetOfMolecules = currentChemFile.Builder.newSetOfMolecules();
            currentMolecule       = currentChemFile.Builder.newMolecule();
            atomEnumeration       = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
        }
Пример #31
0
        /// <summary> Reads a set of coordinates into ChemModel.
        /// 
        /// </summary>
        /// <param name="model">the destination ChemModel
        /// </param>
        /// <throws>  IOException if an I/O error occurs </throws>
        private void readCoordinates(IChemModel model)
        {
            IAtomContainer container = model.Builder.newAtomContainer();
            System.String line = input.ReadLine();
            line = input.ReadLine();
            line = input.ReadLine();
            line = input.ReadLine();
            while (input.Peek() != -1)
            {
                line = input.ReadLine();
                if ((line == null) || (line.IndexOf("-----") >= 0))
                {
                    break;
                }
                int atomicNumber = 0;
                System.IO.StringReader sr = new System.IO.StringReader(line);
                SupportClass.StreamTokenizerSupport token = new SupportClass.StreamTokenizerSupport(sr);
                token.NextToken();

                // ignore first token
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    atomicNumber = (int)token.nval;
                    if (atomicNumber == 0)
                    {

                        // Skip dummy atoms. Dummy atoms must be skipped
                        // if frequencies are to be read because Gaussian
                        // does not report dummy atoms in frequencies, and
                        // the number of atoms is used for reading frequencies.
                        continue;
                    }
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                token.NextToken();

                // ignore third token
                double x = 0.0;
                double y = 0.0;
                double z = 0.0;
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    x = token.nval;
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    y = token.nval;
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    z = token.nval;
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                System.String symbol = "Du";
                try
                {
                    symbol = IsotopeFactory.getInstance(model.Builder).getElementSymbol(atomicNumber);
                }
                catch (System.Exception exception)
                {
                    throw new CDKException("Could not determine element symbol!", exception);
                }
                IAtom atom = model.Builder.newAtom(symbol);
                atom.setPoint3d(new Point3d(x, y, z));
                container.addAtom(atom);
            }
            ISetOfMolecules moleculeSet = model.Builder.newSetOfMolecules();
            moleculeSet.addMolecule(model.Builder.newMolecule(container));
            model.SetOfMolecules = moleculeSet;
        }
Пример #32
0
 /// <summary>  Returns the atom of the given molecule that is closest to the given
 /// coordinates, using an external set of coordinates.
 /// See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets
 /// 
 /// </summary>
 /// <param name="xPosition"> The x coordinate
 /// </param>
 /// <param name="yPosition"> The y coordinate
 /// </param>
 /// <param name="renderingCoordinates"> The set of coordinates to use coming from RendererModel2D
 /// </param>
 /// <returns>            The atom that is closest to the given coordinates
 /// </returns>
 //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
 public static IAtom getClosestAtom(int xPosition, int yPosition, IChemModel model, IAtom ignore, System.Collections.Hashtable renderingCoordinates)
 {
     IAtom closestAtom = null;
     IAtom currentAtom;
     double smallestMouseDistance = -1;
     double mouseDistance;
     double atomX;
     double atomY;
     IAtomContainer all = ChemModelManipulator.getAllInOneContainer(model);
     for (int i = 0; i < all.AtomCount; i++)
     {
         currentAtom = all.getAtomAt(i);
         //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapget_javalangObject'"
         if (renderingCoordinates[currentAtom] == null && currentAtom.getPoint2d() != null)
         {
             renderingCoordinates[currentAtom] = new Point2d(currentAtom.getPoint2d().x, currentAtom.getPoint2d().y);
         }
         //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapget_javalangObject'"
         if (currentAtom != ignore && renderingCoordinates[currentAtom] != null)
         {
             //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapget_javalangObject'"
             atomX = ((Point2d)renderingCoordinates[currentAtom]).x;
             //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMapget_javalangObject'"
             atomY = ((Point2d)renderingCoordinates[currentAtom]).y;
             mouseDistance = System.Math.Sqrt(System.Math.Pow(atomX - xPosition, 2) + System.Math.Pow(atomY - yPosition, 2));
             if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1)
             {
                 smallestMouseDistance = mouseDistance;
                 closestAtom = currentAtom;
             }
         }
     }
     return closestAtom;
 }
Пример #33
0
        //protected internal LoggingTool logger;

        /// <summary> Basic contructor</summary>
        public ChemFileCDO(IChemFile file)
        {
            //logger = new LoggingTool(this);
            currentChemFile = file;
            currentChemSequence = file.Builder.newChemSequence();
            currentChemModel = file.Builder.newChemModel();
            currentSetOfMolecules = file.Builder.newSetOfMolecules();
            currentSetOfReactions = null;
            currentReaction = null;
            currentMolecule = file.Builder.newMolecule();
            atomEnumeration = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
        }
Пример #34
0
        // procedures required by CDOInterface

        /// <summary> Procedure required by the CDOInterface. This function is only
        /// supposed to be called by the JCFL library
        /// </summary>
        public virtual void startDocument()
        {
            //logger.info("New CDO Object");
            currentChemSequence = currentChemFile.Builder.newChemSequence();
            currentChemModel = currentChemFile.Builder.newChemModel();
            currentSetOfMolecules = currentChemFile.Builder.newSetOfMolecules();
            currentMolecule = currentChemFile.Builder.newMolecule();
            atomEnumeration = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
        }
Пример #35
0
 /// <summary> Procedure required by the CDOInterface. This function is only
 /// supposed to be called by the JCFL library
 /// </summary>
 public virtual void startObject(System.String objectType)
 {
     //logger.debug("START:" + objectType);
     if (objectType.Equals("Molecule"))
     {
         if (currentChemModel == null)
             currentChemModel = currentChemFile.Builder.newChemModel();
         if (currentSetOfMolecules == null)
             currentSetOfMolecules = currentChemFile.Builder.newSetOfMolecules();
         currentMolecule = currentChemFile.Builder.newMolecule();
     }
     else if (objectType.Equals("Atom"))
     {
         currentAtom = currentChemFile.Builder.newAtom("H");
         //logger.debug("Atom # " + numberOfAtoms);
         numberOfAtoms++;
     }
     else if (objectType.Equals("Bond"))
     {
         bond_id = null;
         bond_stereo = -99;
     }
     else if (objectType.Equals("Animation"))
     {
         currentChemSequence = currentChemFile.Builder.newChemSequence();
     }
     else if (objectType.Equals("Frame"))
     {
         currentChemModel = currentChemFile.Builder.newChemModel();
     }
     else if (objectType.Equals("SetOfMolecules"))
     {
         currentSetOfMolecules = currentChemFile.Builder.newSetOfMolecules();
         currentMolecule = currentChemFile.Builder.newMolecule();
     }
     else if (objectType.Equals("Crystal"))
     {
         currentMolecule = currentChemFile.Builder.newCrystal(currentMolecule);
     }
     else if (objectType.Equals("a-axis") || objectType.Equals("b-axis") || objectType.Equals("c-axis"))
     {
         crystal_axis_x = 0.0;
         crystal_axis_y = 0.0;
         crystal_axis_z = 0.0;
     }
     else if (objectType.Equals("SetOfReactions"))
     {
         currentSetOfReactions = currentChemFile.Builder.newSetOfReactions();
     }
     else if (objectType.Equals("Reaction"))
     {
         if (currentSetOfReactions == null)
             startObject("SetOfReactions");
         currentReaction = currentChemFile.Builder.newReaction();
     }
     else if (objectType.Equals("Reactant"))
     {
         if (currentReaction == null)
             startObject("Reaction");
         currentMolecule = currentChemFile.Builder.newMolecule();
     }
     else if (objectType.Equals("Product"))
     {
         if (currentReaction == null)
             startObject("Reaction");
         currentMolecule = currentChemFile.Builder.newMolecule();
     }
 }
Пример #36
0
 public static IChemModel[] getAllChemModels(IChemFile file)
 {
     IChemSequence[] sequences = file.ChemSequences;
     int modelCounter = 0;
     int counter = 0;
     IChemModel[] tempModels = null;
     for (int f = 0; f < sequences.Length; f++)
     {
         modelCounter += sequences[f].ChemModelCount;
     }
     IChemModel[] models = new IChemModel[modelCounter];
     for (int f = 0; f < sequences.Length; f++)
     {
         tempModels = sequences[f].ChemModels;
         for (int g = 0; g < tempModels.Length; g++)
         {
             models[counter] = tempModels[g];
             counter++;
         }
     }
     return models;
 }
Пример #37
0
        /// <summary> Reads partial atomic charges and add the to the given ChemModel.</summary>
        private void readPartialCharges(IChemModel model)
        {
            //logger.info("Reading partial atomic charges");
            ISetOfMolecules moleculeSet = model.SetOfMolecules;
            IMolecule molecule = moleculeSet.getMolecule(0);
            System.String line = input.ReadLine(); // skip first line after "Total atomic charges"
            while (input.Peek() != -1)
            {
                line = input.ReadLine();
                //logger.debug("Read charge block line: " + line);
                if ((line == null) || (line.IndexOf("Sum of Mulliken charges") >= 0))
                {
                    //logger.debug("End of charge block found");
                    break;
                }
                System.IO.StringReader sr = new System.IO.StringReader(line);
                SupportClass.StreamTokenizerSupport tokenizer = new SupportClass.StreamTokenizerSupport(sr);
                if (tokenizer.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    int atomCounter = (int)tokenizer.nval;

                    tokenizer.NextToken(); // ignore the symbol

                    double charge = 0.0;
                    if (tokenizer.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                    {
                        charge = (double)tokenizer.nval;
                        //logger.debug("Found charge for atom " + atomCounter + ": " + charge);
                    }
                    else
                    {
                        throw new CDKException("Error while reading charge: expected double.");
                    }
                    IAtom atom = molecule.getAtomAt(atomCounter - 1);
                    atom.setCharge(charge);
                }
            }
        }
Пример #38
0
        /// <summary> Reads a set of vibrations into ChemModel.
        /// 
        /// </summary>
        /// <param name="model">the destination ChemModel
        /// </param>
        /// <throws>  IOException if an I/O error occurs </throws>
        private void readFrequencies(IChemModel model)
        {
            /* This is yet to be ported. Vibrations don't exist yet in CDK.
            String 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(); // skip "Red. masses"
            line = input.readLine(); // skip "Rfc consts"
            line = input.readLine(); // skip "IR Inten"
            while (!line.startsWith(" Atom AN")) {
            // skip all lines upto and including the " Atom AN" line
            line = input.readLine(); // skip
            }
            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();
            } */
        }
Пример #39
0
        /// <summary> Reads NMR nuclear shieldings.</summary>
        private void readNMRData(IChemModel model, System.String labelLine)
        {
            /* FIXME: this is yet to be ported. CDK does not have shielding stuff.
            // Determine label for properties
            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 < frame.getAtomCount(); ++i) {
            String line = input.readLine().trim();
            while (line.indexOf("Isotropic") < 0) {
            if (line == null) {
            return;
            }
            line = input.readLine().trim();
            }
            StringTokenizer st1 = new StringTokenizer(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 = Double.valueOf(st1.nextToken()).doubleValue();
            NMRShielding ns1 = new NMRShielding(label, shielding);
            ((org.openscience.jmol.Atom)frame.getAtomAt(atomIndex)).addProperty(ns1);
            ++atomIndex;
            } */
        }
Пример #40
0
        private IChemModel readChemModel(IChemModel model)
        {
            int[] atoms = new int[1];
            double[] atomxs = new double[1];
            double[] atomys = new double[1];
            double[] atomzs = new double[1];
            double[] atomcharges = new double[1];

            int[] bondatomid1 = new int[1];
            int[] bondatomid2 = new int[1];
            int[] bondorder = new int[1];

            int numberOfAtoms = 0;
            int numberOfBonds = 0;

            try
            {
                System.String line = input.ReadLine();
                while (line != null)
                {
                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(line);
                    System.String command = st.NextToken();
                    if ("!Header".Equals(command))
                    {
                        //logger.warn("Ignoring header");
                    }
                    else if ("!Info".Equals(command))
                    {
                        //logger.warn("Ignoring info");
                    }
                    else if ("!Atoms".Equals(command))
                    {
                        //logger.info("Reading atom block");
                        // determine number of atoms to read
                        try
                        {
                            numberOfAtoms = System.Int32.Parse(st.NextToken());
                            //logger.debug("  #atoms: " + numberOfAtoms);
                            atoms = new int[numberOfAtoms];
                            atomxs = new double[numberOfAtoms];
                            atomys = new double[numberOfAtoms];
                            atomzs = new double[numberOfAtoms];
                            atomcharges = new double[numberOfAtoms];

                            for (int i = 0; i < numberOfAtoms; i++)
                            {
                                line = input.ReadLine();
                                SupportClass.Tokenizer atomInfoFields = new SupportClass.Tokenizer(line);
                                int atomID = System.Int32.Parse(atomInfoFields.NextToken());
                                atoms[atomID] = System.Int32.Parse(atomInfoFields.NextToken());
                                //logger.debug("Set atomic number of atom (" + atomID + ") to: " + atoms[atomID]);
                            }
                        }
                        catch (System.Exception exception)
                        {
                            //logger.error("Error while reading Atoms block");
                            //logger.debug(exception);
                        }
                    }
                    else if ("!Bonds".Equals(command))
                    {
                        //logger.info("Reading bond block");
                        try
                        {
                            // determine number of bonds to read
                            numberOfBonds = System.Int32.Parse(st.NextToken());
                            bondatomid1 = new int[numberOfAtoms];
                            bondatomid2 = new int[numberOfAtoms];
                            bondorder = new int[numberOfAtoms];

                            for (int i = 0; i < numberOfBonds; i++)
                            {
                                line = input.ReadLine();
                                SupportClass.Tokenizer bondInfoFields = new SupportClass.Tokenizer(line);
                                bondatomid1[i] = System.Int32.Parse(bondInfoFields.NextToken());
                                bondatomid2[i] = System.Int32.Parse(bondInfoFields.NextToken());
                                System.String order = bondInfoFields.NextToken();
                                if ("D".Equals(order))
                                {
                                    bondorder[i] = 2;
                                }
                                else if ("S".Equals(order))
                                {
                                    bondorder[i] = 1;
                                }
                                else if ("T".Equals(order))
                                {
                                    bondorder[i] = 3;
                                }
                                else
                                {
                                    // ignore order, i.e. set to single
                                    //logger.warn("Unrecognized bond order, using single bond instead. Found: " + order);
                                    bondorder[i] = 1;
                                }
                            }
                        }
                        catch (System.Exception exception)
                        {
                            //logger.error("Error while reading Bonds block");
                            //logger.debug(exception);
                        }
                    }
                    else if ("!Coord".Equals(command))
                    {
                        //logger.info("Reading coordinate block");
                        try
                        {
                            for (int i = 0; i < numberOfAtoms; i++)
                            {
                                line = input.ReadLine();
                                SupportClass.Tokenizer atomInfoFields = new SupportClass.Tokenizer(line);
                                int atomID = System.Int32.Parse(atomInfoFields.NextToken());
                                double x = System.Double.Parse(atomInfoFields.NextToken());
                                double y = System.Double.Parse(atomInfoFields.NextToken());
                                double z = System.Double.Parse(atomInfoFields.NextToken());
                                atomxs[atomID] = x;
                                atomys[atomID] = y;
                                atomzs[atomID] = z;
                            }
                        }
                        catch (System.Exception exception)
                        {
                            //logger.error("Error while reading Coord block");
                            //logger.debug(exception);
                        }
                    }
                    else if ("!Charges".Equals(command))
                    {
                        //logger.info("Reading charges block");
                        try
                        {
                            for (int i = 0; i < numberOfAtoms; i++)
                            {
                                line = input.ReadLine();
                                SupportClass.Tokenizer atomInfoFields = new SupportClass.Tokenizer(line);
                                int atomID = System.Int32.Parse(atomInfoFields.NextToken());
                                double charge = System.Double.Parse(atomInfoFields.NextToken());
                                atomcharges[atomID] = charge;
                            }
                        }
                        catch (System.Exception exception)
                        {
                            //logger.error("Error while reading Charges block");
                            //logger.debug(exception);
                        }
                    }
                    else if ("!End".Equals(command))
                    {
                        //logger.info("Found end of file");
                        // Store atoms
                        IAtomContainer container = model.Builder.newAtomContainer();
                        for (int i = 0; i < numberOfAtoms; i++)
                        {
                            try
                            {
                                IAtom atom = model.Builder.newAtom(IsotopeFactory.getInstance(container.Builder).getElementSymbol(atoms[i]));
                                atom.AtomicNumber = atoms[i];
                                atom.setPoint3d(new Point3d(atomxs[i], atomys[i], atomzs[i]));
                                atom.setCharge(atomcharges[i]);
                                container.addAtom(atom);
                                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                                //logger.debug("Stored atom: " + atom);
                            }
                            catch (System.Exception exception)
                            {
                                //logger.error("Cannot create an atom with atomic number: " + atoms[i]);
                                //logger.debug(exception);
                            }
                        }

                        // Store bonds
                        for (int i = 0; i < numberOfBonds; i++)
                        {
                            container.addBond(bondatomid1[i], bondatomid2[i], bondorder[i]);
                        }

                        ISetOfMolecules moleculeSet = model.Builder.newSetOfMolecules();
                        moleculeSet.addMolecule(model.Builder.newMolecule(container));
                        model.SetOfMolecules = moleculeSet;

                        return model;
                    }
                    else
                    {
                        //logger.warn("Skipping line: " + line);
                    }

                    line = input.ReadLine();
                }
            }
            catch (System.Exception exception)
            {
                //logger.error("Error while reading file");
                //logger.debug(exception);
            }

            // this should not happen, file is lacking !End command
            return null;
        }
Пример #41
0
 public virtual void createIDs(IChemModel model)
 {
     ICrystal crystal = model.Crystal;
     if (crystal != null)
         createIDs(crystal);
     ISetOfMolecules moleculeSet = model.SetOfMolecules;
     if (moleculeSet != null)
         createIDs(moleculeSet);
     ISetOfReactions reactionSet = model.SetOfReactions;
     if (reactionSet != null)
         createIDs(reactionSet);
 }
Пример #42
0
        /// <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.");
                }
            }
        }