Beispiel #1
0
 public override void write(IChemObject object_Renamed)
 {
     if (object_Renamed is IMolecule)
     {
         try
         {
             ISetOfMolecules som = object_Renamed.Builder.newSetOfMolecules();
             som.addMolecule((IMolecule)object_Renamed);
             writeMolecule(som);
         }
         catch (System.Exception ex)
         {
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             throw new CDKException("Error while writing HIN file: " + ex.Message, ex);
         }
     }
     else if (object_Renamed is ISetOfMolecules)
     {
         try
         {
             writeMolecule((ISetOfMolecules)object_Renamed);
         }
         catch (System.IO.IOException ex)
         {
             //
         }
     }
     else
     {
         throw new CDKException("HINWriter only supports output of Molecule or SetOfMolecule classes.");
     }
 }
Beispiel #2
0
        public virtual void TestGetProperties()
        {
            IChemObject chemObject = NewChemObject();

            Assert.IsNotNull(chemObject.GetProperties());
            Assert.AreEqual(0, chemObject.GetProperties().Count());
        }
Beispiel #3
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IAtomType && second is IAtomType))
            {
                return(null);
            }
            var firstElem  = (IAtomType)first;
            var secondElem = (IAtomType)second;
            var totalDiff  = new ChemObjectDifference("AtomTypeDiff");

            totalDiff.AddChild(StringDifference.Construct("N", firstElem.AtomTypeName, secondElem.AtomTypeName));
            totalDiff.AddChild(BondOrderDifference.Construct("MBO", firstElem.MaxBondOrder,
                                                             secondElem.MaxBondOrder));
            totalDiff
            .AddChild(DoubleDifference.Construct("BOS", firstElem.BondOrderSum, secondElem.BondOrderSum));
            totalDiff
            .AddChild(IntegerDifference.Construct("FC", firstElem.FormalCharge, secondElem.FormalCharge));
            totalDiff.AddChild(AtomTypeHybridizationDifference.Construct("H", firstElem.Hybridization,
                                                                         secondElem.Hybridization));
            totalDiff.AddChild(IntegerDifference.Construct("NC", firstElem.FormalNeighbourCount,
                                                           secondElem.FormalNeighbourCount));
            totalDiff.AddChild(DoubleDifference.Construct("CR", firstElem.CovalentRadius,
                                                          secondElem.CovalentRadius));
            totalDiff.AddChild(IntegerDifference.Construct("V", firstElem.Valency, secondElem.Valency));
            totalDiff.AddChild(IsotopeDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
 private static void SetIfMissing(IChemObject chemObject, string key, string val)
 {
     if (chemObject.GetProperty <string>(key) == null)
     {
         chemObject.SetProperty(key, val);
     }
 }
Beispiel #5
0
        public virtual void TestSetNotification_bool()
        {
            IChemObject chemObject = NewChemObject();

            chemObject.Notification = false;
            Assert.IsFalse(chemObject.Notification);
        }
        public static void TestSetAtoms_RemoveListener(IChemObject newChemObject)
        {
            IAtomContainer container = (IAtomContainer)newChemObject;

            IAtom[] atoms = new IAtom[4];
            atoms[0] = container.Builder.NewAtom("C");
            atoms[1] = container.Builder.NewAtom("C");
            atoms[2] = container.Builder.NewAtom("C");
            atoms[3] = container.Builder.NewAtom("O");
            container.SetAtoms(atoms);

            // if an atom changes, the atomcontainer will throw a change event too
            ChemObjectListener listener = new ChemObjectListener();

            container.Listeners.Add(listener);
            Assert.IsFalse(listener.Changed);

            // ok, change the atom, and make sure we do get an event
            atoms[0].AtomTypeName = "C.sp2";
            Assert.IsFalse(listener.Changed);

            // reset the listener, overwrite the atoms, and change an old atom.
            // if all is well, we should not get a change event this time
            listener.Reset();
            Assert.IsFalse(listener.Changed); // make sure the reset worked
            container.SetAtoms(Array.Empty <IAtom>());
            atoms[1].AtomTypeName = "C.sp2";  // make a change to an old atom
            Assert.IsFalse(listener.Changed); // but no change event should happen
        }
        public static void TestGetListenerCount(IChemObject chemObject)
        {
            ChemObjectListener listener = new ChemObjectListener();

            chemObject.Listeners.Add(listener);
            Assert.AreEqual(0, chemObject.Listeners.Count);
        }
Beispiel #8
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IBond && second is IBond))
            {
                return(null);
            }
            IBond           firstB    = (IBond)first;
            IBond           secondB   = (IBond)second;
            IDifferenceList totalDiff = new ChemObjectDifference("BondDiff");

            totalDiff.AddChild(BondOrderDifference.Construct("order", firstB.Order, secondB.Order));
            totalDiff.AddChild(IntegerDifference.Construct("atomCount", firstB.Atoms.Count, secondB.Atoms.Count));
            if (firstB.Atoms.Count == secondB.Atoms.Count)
            {
                totalDiff.AddChild(AtomDiff.Difference(firstB.Begin, secondB.Begin));
                totalDiff.AddChild(AtomDiff.Difference(firstB.End, secondB.End));
                for (int i = 2; i < firstB.Atoms.Count; i++)
                {
                    totalDiff.AddChild(AtomDiff.Difference(firstB.Atoms[i], secondB.Atoms[i]));
                }
            }
            totalDiff.AddChild(ElectronContainerDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Beispiel #9
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 + ".");
     }
 }
Beispiel #10
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IAtom && second is IAtom))
            {
                return(null);
            }
            IAtom firstElem  = (IAtom)first;
            IAtom secondElem = (IAtom)second;
            ChemObjectDifference totalDiff = new ChemObjectDifference("AtomDiff");

            totalDiff.AddChild(IntegerDifference.Construct("H", firstElem.ImplicitHydrogenCount,
                                                           secondElem.ImplicitHydrogenCount));
            totalDiff
            .AddChild(IntegerDifference.Construct("SP", (int)firstElem.StereoParity, (int)secondElem.StereoParity));
            totalDiff.AddChild(Point2DDifference.Construct("2D", firstElem.Point2D, secondElem.Point2D));
            totalDiff.AddChild(Point3DDifference.Construct("3D", firstElem.Point3D, secondElem.Point3D));
            totalDiff.AddChild(Point3DDifference.Construct("F3D", firstElem.FractionalPoint3D,
                                                           secondElem.FractionalPoint3D));
            totalDiff.AddChild(DoubleDifference.Construct("C", firstElem.Charge, secondElem.Charge));
            totalDiff.AddChild(AtomTypeDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Beispiel #11
0
 public override void Write(IChemObject obj)
 {
     if (obj is IAtomContainer)
     {
         try
         {
             IChemObjectSet <IAtomContainer> som = obj.Builder.NewAtomContainerSet();
             som.Add((IAtomContainer)obj);
             WriteAtomContainer(som);
         }
         catch (Exception ex)
         {
             if (!(ex is ArgumentException | ex is IOException))
             {
                 throw;
             }
             throw new CDKException("Error while writing HIN file: " + ex.Message, ex);
         }
     }
     else if (obj is IEnumerableChemObject <IAtomContainer> )
     {
         try
         {
             WriteAtomContainer((IEnumerableChemObject <IAtomContainer>)obj);
         }
         catch (IOException)
         {
             //
         }
     }
     else
     {
         throw new CDKException("HINWriter only supports output of Molecule or SetOfMolecule classes.");
     }
 }
Beispiel #12
0
        public virtual void TestGetRingSize()
        {
            IChemObject obj = NewChemObject();
            IRing       r   = obj.Builder.NewRing(5, "C");

            Assert.AreEqual(5, r.RingSize);
        }
Beispiel #13
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 + ".");
     }
 }
Beispiel #14
0
        public virtual void TestGetFlagValue()
        {
            IChemObject chemObject = NewChemObject();

            chemObject.Flag = CDKConstants.ISALIPHATIC, true;
            Assert.AreNotSame((short)0, chemObject.GetFlagValue());
        }
Beispiel #15
0
        //[ExpectedException(typeof(ArgumentException))]
        public virtual void TestGetProperty_Object_ClassCast()
        {
            IChemObject chemObject = NewChemObject();

            chemObject.SetProperty("dummy", 5);
            Assert.IsNull(chemObject.GetProperty <object>("dummy") as string);
        }
Beispiel #16
0
        public void TestNewChemObject_IChemObject()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IChemObject        model   = builder.NewChemObject(builder.NewChemObject());

            Assert.IsNotNull(model);
        }
Beispiel #17
0
        public IChemObject[] QueryConnected(IChemObject obj)
        {
            List <IChemObject> objs = new List <IChemObject>();

            if (obj is IAtom)
            {
                // find connected bonds
                foreach (IBond bond in renderContext.bonds)
                {
                    IAtom[] atoms = bond.getAtoms();
                    foreach (IAtom atom in atoms)
                    {
                        if (atom == obj)
                        {
                            // add bond
                            objs.Add(bond);
                            // add all other atoms on this bond
                            foreach (IAtom a in atoms)
                            {
                                if (a != obj)
                                {
                                    objs.Add(a);
                                }
                            }
                        }
                    }
                }
            }
            return(objs.ToArray());
        }
Beispiel #18
0
 /// <summary> Writes a IChemObject to the MDL molfile formated output.
 /// It can only output ChemObjects of type ChemFile, Molecule and
 /// SetOfMolecules.
 ///
 /// </summary>
 /// <param name="object">class must be of type ChemFile, Molecule or SetOfMolecules.
 ///
 /// </param>
 /// <seealso cref="org.openscience.cdk.ChemFile">
 /// </seealso>
 public override void write(IChemObject object_Renamed)
 {
     if (object_Renamed is ISetOfMolecules)
     {
         writeSetOfMolecules((ISetOfMolecules)object_Renamed);
     }
     else if (object_Renamed is IChemFile)
     {
         writeChemFile((IChemFile)object_Renamed);
     }
     else if (object_Renamed is IMolecule)
     {
         try
         {
             bool[] isVisible = new bool[((IMolecule)object_Renamed).AtomCount];
             for (int i = 0; i < isVisible.Length; i++)
             {
                 isVisible[i] = true;
             }
             writeMolecule((IMolecule)object_Renamed, isVisible);
         }
         catch (System.Exception ex)
         {
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             //logger.error(ex.Message);
             //logger.debug(ex);
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             throw new CDKException("Exception while writing MDL file: " + ex.Message, ex);
         }
     }
     else
     {
         throw new CDKException("Only supported is writing of ChemFile, SetOfMolecules, AtomContainer and Molecule objects.");
     }
 }
Beispiel #19
0
        private void WriteProperties(IChemObject obj, CMLElement cmlElement)
        {
            var props = obj.GetProperties();

            foreach (var key in props.Keys)
            {
                var stringKey = (string)key;
                switch (stringKey)
                {
                case CDKPropertyName.Title:
                    // don't output this one. It's covered by AddTitle()
                    break;

                default:
                    if (!(stringKey.StartsWith("org.openscience.cdk", StringComparison.Ordinal)))
                    {
                        object value  = props[key];
                        var    scalar = new CMLScalar();
                        this.CheckPrefix(scalar);
                        scalar.Title = (string)key;
                        scalar.Value = value.ToString();
                        cmlElement.Add(scalar);
                    }
                    break;
                }
            }
        }
Beispiel #20
0
        public void TestMatchAgainstItself()
        {
            var    m_atom1 = new Mock <IChemObject>(); IChemObject atom1 = m_atom1.Object;
            string result = ChemObjectDiff.Diff(atom1, atom1);

            AssertZeroLength(result);
        }
Beispiel #21
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)
        {
            customizeJob();

            try
            {
                if (object_Renamed is IChemSequence)
                {
                    return(readReactions(false));
                }
                else if (object_Renamed is IChemModel)
                {
                    return(readReactions(true));
                }
                else if (object_Renamed is IChemFile)
                {
                    IChemFile chemFile = object_Renamed.Builder.newChemFile();
                    chemFile.addChemSequence((ChemSequence)readReactions(false));
                    return(chemFile);
                }
            }
            catch (System.IO.IOException exception)
            {
                //UPGRADE_ISSUE: Method 'java.io.LineNumberReader.getLineNumber' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioLineNumberReadergetLineNumber'"
                System.String message = "Error while reading file, line number: ";// +input.getLineNumber();
                //logger.error(message);
                //logger.debug(exception);
                throw new CDKException(message, exception);
            }
            throw new CDKException("Only supported are ChemSequence and ChemModel.");
        }
Beispiel #22
0
 private void SerializeChemObjectFields(INode rdfObject, IChemObject obj)
 {
     if (obj.Id != null)
     {
         g.Assert(new Triple(rdfObject, P_IDENTIFIER, g.CreateLiteralNode(obj.Id)));
     }
 }
Beispiel #23
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IAtomContainer && second is IAtomContainer))
            {
                return(null);
            }
            var firstAC   = (IAtomContainer)first;
            var secondAC  = (IAtomContainer)second;
            var totalDiff = new ChemObjectDifference("AtomContainerDiff");

            totalDiff.AddChild(IntegerDifference.Construct("atomCount", firstAC.Atoms.Count, secondAC.Atoms.Count));
            if (firstAC.Atoms.Count == secondAC.Atoms.Count)
            {
                for (int i = 0; i < firstAC.Atoms.Count; i++)
                {
                    totalDiff.AddChild(AtomDiff.Difference(firstAC.Atoms[i], secondAC.Atoms[i]));
                }
            }
            totalDiff.AddChild(IntegerDifference.Construct("electronContainerCount", firstAC.GetElectronContainers().Count(),
                                                           secondAC.GetElectronContainers().Count()));
            if (firstAC.GetElectronContainers().Count() == secondAC.GetElectronContainers().Count())
            {
                for (int i = 0; i < firstAC.GetElectronContainers().Count(); i++)
                {
                    if (firstAC.GetElectronContainers().ElementAt(i) is IBond &&
                        secondAC.GetElectronContainers().ElementAt(i) is IBond)
                    {
                        totalDiff.AddChild(BondDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                               secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else if (firstAC.GetElectronContainers().ElementAt(i) is ILonePair &&
                             secondAC.GetElectronContainers().ElementAt(i) is ILonePair)
                    {
                        totalDiff.AddChild(LonePairDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                   secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else if (firstAC.GetElectronContainers().ElementAt(i) is ISingleElectron &&
                             secondAC.GetElectronContainers().ElementAt(i) is ISingleElectron)
                    {
                        totalDiff.AddChild(SingleElectronDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                         secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else
                    {
                        totalDiff.AddChild(ElectronContainerDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                            secondAC.GetElectronContainers().ElementAt(i)));
                    }
                }
            }
            totalDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Beispiel #24
0
        public virtual void TestClone_PropertyNull()
        {
            IChemObject chemObject = NewChemObject();
            string      key        = "NullProperty";

            chemObject.SetProperty(key, null);
            chemObject.Clone();
        }
Beispiel #25
0
        public virtual void TestGetFlags_Array()
        {
            IChemObject chemObject = NewChemObject();

            chemObject.IsPlaced = true;
            bool[] flags = chemObject.GetFlags();
            Assert.IsTrue(flags[1]);
        }
Beispiel #26
0
        public virtual void TestSetID_String()
        {
            IChemObject chemObject = NewChemObject();
            string      id         = "objectX";

            chemObject.Id = id;
            Assert.AreEqual(id, chemObject.Id);
        }
Beispiel #27
0
        public virtual void TestGetListenerCount()
        {
            IChemObject             chemObject1 = NewChemObject();
            DummyChemObjectListener listener    = new DummyChemObjectListener(this);

            chemObject1.Listeners.Add(listener);
            Assert.AreEqual(1, chemObject1.Listeners.Count);
        }
Beispiel #28
0
        public virtual void TestShallowCopy()
        {
            IChemObject chemObject = NewChemObject();
            object      clone      = chemObject.Clone();

            Assert.IsNotNull(clone);
            Assert.IsTrue(clone is IChemObject);
        }
Beispiel #29
0
 public virtual bool accepts(IChemObject object_Renamed)
 {
     if (object_Renamed is IMolecule)
     {
         return(true);
     }
     return(false);
 }
Beispiel #30
0
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IMolecule)
     {
         return(readMolecule(object_Renamed.Builder));
     }
     return(null);
 }
Beispiel #31
0
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemFile)
     {
         IChemFile cf = (IChemFile)object_Renamed;
         try
         {
             cf = readChemFile(cf);
         }
         catch (System.IO.IOException exception)
         {
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             System.String error = "Input/Output error while reading from input: " + exception.Message;
             //logger.error(error);
             //logger.debug(exception);
             throw new CDKException(error, exception);
         }
         return cf;
     }
     else
     {
         throw new CDKException("Only supported is reading of ChemFile.");
     }
 }
 public abstract void write(IChemObject param1);
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemSequence)
     {
         return readChemSequence((IChemSequence)object_Renamed);
     }
     else if (object_Renamed is IChemFile)
     {
         return readChemFile((IChemFile)object_Renamed);
     }
     else
     {
         throw new CDKException("Object " + object_Renamed.GetType().FullName + " is not supported");
     }
 }
Beispiel #34
0
 /* (non-Javadoc) (Javadoc is automaticly inherited from the link below)
 * @see org.openscience.cdk.io.ChemObjectReader#read(org.openscience.cdk.ChemObject)
 */
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemFile)
     {
         try
         {
             return (IChemObject)readChemFile((IChemFile)object_Renamed);
         }
         catch (System.IO.IOException e)
         {
             return null;
         }
     }
     else
     {
         throw new CDKException("Only supported is reading of ChemFile objects.");
     }
 }
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IMolecule)
     {
         return readMolecule(object_Renamed.Builder);
     }
     return null;
 }
Beispiel #36
0
 /// <summary> Read a ChemFile from input
 /// 
 /// </summary>
 /// <returns> the content in a ChemFile object
 /// </returns>
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemFile)
     {
         IChemFile cf = (IChemFile)object_Renamed;
         try
         {
             cf = readChemFile(cf);
         }
         catch (System.IO.IOException e)
         {
             //logger.error("Input/Output error while reading from input.");
         }
         return cf;
     }
     else
     {
         throw new CDKException("Only supported is reading of ChemFile.");
     }
 }
Beispiel #37
0
 /// <summary> Writes a IChemObject to the MDL RXN file formated output. 
 /// It can only output ChemObjects of type Reaction
 /// 
 /// </summary>
 /// <param name="object">class must be of type Molecule or SetOfMolecules.
 /// 
 /// </param>
 /// <seealso cref="org.openscience.cdk.ChemFile">
 /// </seealso>
 public override void write(IChemObject object_Renamed)
 {
     if (object_Renamed is IReaction)
     {
         writeReaction((IReaction)object_Renamed);
     }
     else
     {
         throw new CDKException("Only supported is writing Reaction objects.");
     }
 }
Beispiel #38
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="oObj"> The object that subclasses IChemObject
 /// </param>
 /// <returns>      The IChemObject read  
 /// </returns>
 /// <exception cref="CDKException"> 
 /// 
 /// </exception>
 public override IChemObject read(IChemObject oObj)
 {
     if (oObj is IChemFile)
     {
         if (pdbFactory == null)
         {
             try
             {
                 pdbFactory = AtomTypeFactory.getInstance("pdb_atomtypes.xml", ((IChemFile)oObj).Builder);
             }
             catch (System.Exception exception)
             {
                 //logger.debug(exception);
                 //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                 throw new CDKException("Could not setup list of PDB atom types! " + exception.Message);
             }
         }
         return readChemFile((IChemFile)oObj);
     }
     else
     {
         throw new CDKException("Only supported is reading of ChemFile objects.");
     }
 }
		private static string GetNeutralChange(IChemObject ac, int hydrogensAdded)
		{
			var neutralLoss = "";
			if (ac.getProperty("NlElementalComposition") != null && (string)ac.getProperty("NlElementalComposition") != "")
			{
				neutralLoss = "-" + ac.getProperty("NlElementalComposition") + " ";
			}

			var signString = hydrogensAdded < 0 ? "-" : "+";

			switch (Math.Abs(hydrogensAdded))
			{
				case 0:
					return neutralLoss;
				case 1:
					return string.Format("{0}{1}H", neutralLoss, signString);
				default:
					return string.Format("{0}{1}{2}H", neutralLoss, signString, Math.Abs(hydrogensAdded));
			}
		}		
Beispiel #40
0
 /// <summary> Writes the content from object to output.
 /// 
 /// </summary>
 /// <param name="object"> IChemObject of which the data is outputted.
 /// </param>
 public override void write(IChemObject object_Renamed)
 {
     if (object_Renamed is ISetOfMolecules)
     {
         writeSetOfMolecules((ISetOfMolecules)object_Renamed);
     }
     else if (object_Renamed is IMolecule)
     {
         writeMolecule((IMolecule)object_Renamed);
     }
     else
     {
         throw new CDKException("Only supported is writing of ChemFile and Molecule objects.");
     }
 }
Beispiel #41
0
 public virtual bool accepts(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemFile)
     {
     }
     else if (object_Renamed is IChemModel)
     {
         return true;
     }
     return false;
 }
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemModel)
     {
         return (IChemObject)readChemModel((IChemModel)object_Renamed);
     }
     else
     {
         throw new CDKException("Only supported is ChemModel.");
     }
 }
Beispiel #43
0
 /// <summary> Constructs an unconnected lone pair.
 /// 
 /// </summary>
 /// <param name="objectOne">The first IChemObject of the mapping
 /// </param>
 /// <param name="objectTwo">The second IChemObject of the mapping
 /// </param>
 public Mapping(IChemObject objectOne, IChemObject objectTwo)
 {
     relation = new IChemObject[2];
     relation[0] = objectOne;
     relation[1] = objectTwo;
 }
 public virtual bool accepts(IChemObject object_Renamed)
 {
     if (object_Renamed is IMolecule)
     {
         return true;
     }
     return false;
 }
 public virtual IMapping newMapping(IChemObject objectOne, IChemObject objectTwo)
 {
     return new Mapping(objectOne, objectTwo);
 }
 public override void write(IChemObject object_Renamed)
 {
     if (object_Renamed is IMolecule)
     {
         try
         {
             writeMolecule((IMolecule)object_Renamed);
         }
         catch (System.Exception ex)
         {
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             //logger.error(ex.Message);
             //logger.debug(ex);
         }
     }
     else
     {
         throw new CDKException("Only supported is writing of Molecule objects.");
     }
 }
 public IChemObject[] QueryConnected(IChemObject obj)
 {
     List<IChemObject> objs = new List<IChemObject>();
     if (obj is IAtom)
     {
         // find connected bonds
         foreach (IBond bond in renderContext.bonds)
         {
             IAtom[] atoms = bond.getAtoms();
             foreach (IAtom atom in atoms)
             {
                 if (atom == obj)
                 {
                     // add bond
                     objs.Add(bond);
                     // add all other atoms on this bond
                     foreach (IAtom a in atoms)
                     {
                         if (a != obj)
                             objs.Add(a);
                     }
                 }
             }
         }
     }
     return objs.ToArray();
 }
Beispiel #48
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 + ".");
     }
 }
 public abstract IChemObject read(IChemObject param1);
Beispiel #50
0
 public virtual bool accepts(IChemObject object_Renamed)
 {
     if (object_Renamed is ChemSequence)
     {
         return true;
     }
     else if (object_Renamed is ChemModel)
     {
         return true;
     }
     else if (object_Renamed is ChemFile)
     {
         return true;
     }
     else if (object_Renamed == null)
     {
         //logger.warn("MACiEReader can not read null objects.");
     }
     else
     {
         //logger.warn("MACiEReader can not read IChemObject of type: ", object_Renamed.GetType().FullName);
     }
     return false;
 }
Beispiel #51
0
 private void addDictRefedAnnotation(IChemObject object_Renamed, System.String type, System.String values)
 {
     SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(values, ",");
     while (tokenizer.HasMoreTokens())
     {
         System.String token = tokenizer.NextToken();
         object_Renamed.setProperty(new DictRef("macie:" + type, token), token);
         //logger.debug("Added dict ref ", token, " to ", object_Renamed.GetType().FullName);
     }
 }
Beispiel #52
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 + ".");
     }
 }
 /// <summary> get the IAtom which is mapped
 /// 
 /// </summary>
 /// <param name="reaction">  The IReaction which contains the mapping 
 /// </param>
 /// <param name="chemObject">The IChemObject which will be searched its mapped IChemObject
 /// </param>
 /// <returns>           The mapped IChemObject
 /// </returns>
 public static IChemObject getMappedChemObject(IReaction reaction, IChemObject chemObject)
 {
     IMapping[] mappings = reaction.Mappings;
     for (int i = 0; i < mappings.Length; i++)
     {
         IMapping mapping = mappings[i];
         IChemObject[] map = mapping.RelatedChemObjects;
         if (map[0].Equals(chemObject))
         {
             return map[1];
         }
         else if (map[1].Equals(chemObject))
             return map[0];
     }
     return null;
 }
        private void BuildNodes(TreeNode rootNode, IChemObject[] objects)
        {
            foreach (IChemObject obj in objects)
            {
                TreeNode node;
                if (obj is IChemSequence)
                {
                    IChemSequence seq = (IChemSequence)obj;
                    node = new TreeNode(obj.GetType().Name + ":" + seq.ID);
                    BuildNodes(node, seq.ChemModels);
                }
                else if (obj is IChemModel)
                {
                    IChemModel mdl = (IChemModel)obj;
                    node = new TreeNode(mdl.GetType().Name + ":" + mdl.ID);
                    if (mdl.Crystal != null)
                        node.Nodes.Add(mdl.Crystal.GetType().Name + ":" + mdl.Crystal.ID);
                    else
                        node.Nodes.Add("ICrystal:null");
                    if (mdl.RingSet != null)
                        node.Nodes.Add(mdl.RingSet.GetType().Name + ":" + mdl.RingSet.ID);
                    else
                        node.Nodes.Add("IRingSet:null");
                    if (mdl.SetOfReactions != null)
                        node.Nodes.Add(mdl.SetOfReactions.GetType().Name + ":" + mdl.SetOfReactions.ID);
                    else
                        node.Nodes.Add("ISetOfReactions:null");
                    BuildNodes(node, mdl.SetOfMolecules.Molecules);
                }
                else if (obj is IMolecule)
                {
                    IMolecule mol = (IMolecule)obj;
                    node = new TreeNode(mol.GetType().Name + ":" + mol.ID);
                    BuildNodes(node, mol.Atoms);
                    BuildNodes(node, mol.Bonds);
                }
                else if (obj is IAtom)
                {
                    IAtom atom = (IAtom)obj;
                    node = new TreeNode(atom.GetType().Name + ":" + atom.ID);
                }
                else if (obj is IBond)
                {
                    IBond bond = (IBond)obj;
                    node = new TreeNode(bond.GetType().Name + ":" + bond.ID);
                }
                else
                    node = new TreeNode(obj.GetType().Name + ":" + obj.ID);

                rootNode.Nodes.Add(node);
            }
        }
Beispiel #55
0
 /// <summary> reads the content from a XYZ input. It can only return a
 /// IChemObject of type ChemFile
 /// 
 /// </summary>
 /// <param name="object">class must be of type ChemFile
 /// 
 /// </param>
 /// <seealso cref="IChemFile">
 /// </seealso>
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemFile)
     {
         return (IChemObject)readChemFile((IChemFile)object_Renamed);
     }
     else
     {
         throw new CDKException("Only supported is reading of ChemFile objects.");
     }
 }
Beispiel #56
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)
        {
            customizeJob();

            try
            {
                if (object_Renamed is IChemSequence)
                {
                    return readReactions(false);
                }
                else if (object_Renamed is IChemModel)
                {
                    return readReactions(true);
                }
                else if (object_Renamed is IChemFile)
                {
                    IChemFile chemFile = object_Renamed.Builder.newChemFile();
                    chemFile.addChemSequence((ChemSequence)readReactions(false));
                    return chemFile;
                }
            }
            catch (System.IO.IOException exception)
            {
                //UPGRADE_ISSUE: Method 'java.io.LineNumberReader.getLineNumber' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioLineNumberReadergetLineNumber'"
                System.String message = "Error while reading file, line number: ";// +input.getLineNumber();
                //logger.error(message);
                //logger.debug(exception);
                throw new CDKException(message, exception);
            }
            throw new CDKException("Only supported are ChemSequence and ChemModel.");
        }
 /// <summary>  Returns a IChemObject of type object bye reading from
 /// the input. 
 /// 
 /// The function supports only reading of ChemFile's.
 /// 
 /// </summary>
 /// <param name="object"> IChemObject that types the class to return.
 /// </param>
 /// <throws>     Exception when a IChemObject is requested that cannot be read. </throws>
 public override IChemObject read(IChemObject object_Renamed)
 {
     if (object_Renamed is IChemFile)
         return (IChemObject)readChemFile((IChemFile)object_Renamed);
     else
         throw new CDKException("Only ChemFile objects can be read.");
 }
Beispiel #58
0
 public override void write(IChemObject object_Renamed)
 {
     if (object_Renamed is IMolecule)
     {
         try
         {
             ISetOfMolecules som = object_Renamed.Builder.newSetOfMolecules();
             som.addMolecule((IMolecule)object_Renamed);
             writeMolecule(som);
         }
         catch (System.Exception ex)
         {
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             throw new CDKException("Error while writing HIN file: " + ex.Message, ex);
         }
     }
     else if (object_Renamed is ISetOfMolecules)
     {
         try
         {
             writeMolecule((ISetOfMolecules)object_Renamed);
         }
         catch (System.IO.IOException ex)
         {
             //
         }
     }
     else
     {
         throw new CDKException("HINWriter only supports output of Molecule or SetOfMolecule classes.");
     }
 }
Beispiel #59
0
 /// <summary> Writes a IChemObject to the MDL molfile formated output. 
 /// It can only output ChemObjects of type ChemFile, Molecule and
 /// SetOfMolecules.
 /// 
 /// </summary>
 /// <param name="object">class must be of type ChemFile, Molecule or SetOfMolecules.
 /// 
 /// </param>
 /// <seealso cref="org.openscience.cdk.ChemFile">
 /// </seealso>
 public override void write(IChemObject object_Renamed)
 {
     if (object_Renamed is ISetOfMolecules)
     {
         writeSetOfMolecules((ISetOfMolecules)object_Renamed);
     }
     else if (object_Renamed is IChemFile)
     {
         writeChemFile((IChemFile)object_Renamed);
     }
     else if (object_Renamed is IMolecule)
     {
         try
         {
             bool[] isVisible = new bool[((IMolecule)object_Renamed).AtomCount];
             for (int i = 0; i < isVisible.Length; i++)
             {
                 isVisible[i] = true;
             }
             writeMolecule((IMolecule)object_Renamed, isVisible);
         }
         catch (System.Exception ex)
         {
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             //logger.error(ex.Message);
             //logger.debug(ex);
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             throw new CDKException("Exception while writing MDL file: " + ex.Message, ex);
         }
     }
     else
     {
         throw new CDKException("Only supported is writing of ChemFile, SetOfMolecules, AtomContainer and Molecule objects.");
     }
 }
        /// <summary> Description of the Method
        /// 
        /// </summary>
        /// <param name="object">Description of the Parameter
        /// </param>
        /// <returns> Description of the Return Value
        /// </returns>
        /// <throws>  CDKException Description of the Exception </throws>
        public override IChemObject read(IChemObject object_Renamed)
        {
            customizeJob();

            if (object_Renamed is IChemFile)
            {
                IChemFile file = (IChemFile)object_Renamed;
                try
                {
                    file = readChemFile(file);
                }
                catch (System.IO.IOException exception)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    throw new CDKException("Error while reading file: " + exception.ToString(), exception);
                }
                return file;
            }
            else
            {
                throw new CDKException("Reading of a " + object_Renamed.GetType().FullName + " is not supported.");
            }
        }