Exemplo n.º 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.");
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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 + ".");
     }
 }
Exemplo n.º 5
0
        /// <summary> Partitions the atoms in an AtomContainer into covalently connected components.
        ///
        /// </summary>
        /// <param name="atomContainer"> The AtomContainer to be partitioned into connected components, i.e. molecules
        /// </param>
        /// <returns>                 A SetOfMolecules.
        ///
        /// </returns>
        /// <cdk.dictref>    blue-obelisk:graphPartitioning </cdk.dictref>
        public static ISetOfMolecules partitionIntoMolecules(IAtomContainer atomContainer)
        {
            IAtomContainer     ac         = atomContainer.Builder.newAtomContainer();
            IAtom              atom       = null;
            IElectronContainer eContainer = null;
            IMolecule          molecule   = null;
            ISetOfMolecules    molecules  = atomContainer.Builder.newSetOfMolecules();

            System.Collections.ArrayList sphere = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            for (int f = 0; f < atomContainer.AtomCount; f++)
            {
                atom = atomContainer.getAtomAt(f);
                atom.setFlag(CDKConstants.VISITED, false);
                ac.addAtom(atom);
            }
            IElectronContainer[] eContainers = atomContainer.ElectronContainers;
            for (int f = 0; f < eContainers.Length; f++)
            {
                eContainer = eContainers[f];
                eContainer.setFlag(CDKConstants.VISITED, false);
                ac.addElectronContainer(eContainer);
            }
            while (ac.AtomCount > 0)
            {
                atom     = ac.getAtomAt(0);
                molecule = atomContainer.Builder.newMolecule();
                sphere.Clear();
                sphere.Add(atom);
                atom.setFlag(CDKConstants.VISITED, true);
                PathTools.breadthFirstSearch(ac, sphere, molecule);
                molecules.addMolecule(molecule);
                ac.remove(molecule);
            }
            return(molecules);
        }
Exemplo n.º 6
0
 /// <summary> Writes a SetOfMolecules to an OutputStream for the reaction.
 ///
 /// </summary>
 /// <param name="som"> The SetOfMolecules that is written to an OutputStream
 /// </param>
 private void writeSetOfMolecules(ISetOfMolecules som)
 {
     for (int i = 0; i < som.MoleculeCount; i++)
     {
         IMolecule mol = som.getMolecule(i);
         for (int j = 0; j < som.getMultiplier(i); j++)
         {
             //MemoryStream ms = new MemoryStream();
             //StreamWriter sw = new StreamWriter(ms);
             writer.Write("$MOL\n");
             MDLWriter mdlwriter = null;
             try
             {
                 mdlwriter = new MDLWriter(writer);
             }
             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 creating MDLWriter: " + ex.Message, ex);
             }
             mdlwriter.write(mol);
             //writer.Write(sw.ToString());
         }
     }
 }
Exemplo n.º 7
0
 /// <summary> Constructs an empty, forward reaction.</summary>
 public Reaction()
 {
     this.reactants    = new SetOfMolecules();
     this.products     = new SetOfMolecules();
     this.agents       = new SetOfMolecules();
     this.map          = new Mapping[growArraySize];
     mappingCount      = 0;
     reactionDirection = IReaction_Fields.FORWARD;
 }
Exemplo n.º 8
0
 /// <summary>  Adds all molecules in the SetOfMolecules to this container.
 ///
 /// </summary>
 /// <param name="moleculeSet"> The SetOfMolecules
 /// </param>
 public virtual void add(ISetOfMolecules moleculeSet)
 {
     IMolecule[] mols = moleculeSet.Molecules;
     for (int i = 0; i < mols.Length; i++)
     {
         addMolecule(mols[i]);
     }
     /* notifyChanged() called in super.addAtomContainer() */
 }
Exemplo n.º 9
0
        public static IChemModel newChemModel(IAtomContainer molecule)
        {
            IChemModel      model       = molecule.Builder.newChemModel();
            ISetOfMolecules moleculeSet = model.Builder.newSetOfMolecules();

            moleculeSet.addAtomContainer(molecule);
            model.SetOfMolecules = moleculeSet;
            return(model);
        }
Exemplo n.º 10
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());
        }
Exemplo n.º 11
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());
        }
        public static ISetOfMolecules getAllMolecules(ISetOfReactions set_Renamed)
        {
            ISetOfMolecules moleculeSet = set_Renamed.Builder.newSetOfMolecules();

            IReaction[] reactions = set_Renamed.Reactions;
            for (int i = 0; i < reactions.Length; i++)
            {
                IReaction reaction = reactions[i];
                moleculeSet.add(ReactionManipulator.getAllMolecules(reaction));
            }
            return(moleculeSet);
        }
Exemplo n.º 13
0
        /// <summary> Returns all the AtomContainer's of a ChemModel.</summary>
        public static IAtomContainer[] getAllAtomContainers(IChemModel chemModel)
        {
            ISetOfMolecules moleculeSet = chemModel.Builder.newSetOfMolecules();

            if (chemModel.SetOfMolecules != null)
            {
                moleculeSet.add(chemModel.SetOfMolecules);
            }
            if (chemModel.SetOfReactions != null)
            {
                moleculeSet.add(SetOfReactionsManipulator.getAllMolecules(chemModel.SetOfReactions));
            }
            return(SetOfMoleculesManipulator.getAllAtomContainers(moleculeSet));
        }
Exemplo n.º 14
0
 /// <summary> Writes a list of molecules to an OutputStream
 ///
 /// </summary>
 /// <param name="som"> SetOfMolecules that is written to an OutputStream
 /// </param>
 public virtual void writeSetOfMolecules(ISetOfMolecules som)
 {
     IMolecule[] molecules = som.Molecules;
     writeMolecule(molecules[0]);
     for (int i = 1; i <= som.MoleculeCount - 1; i++)
     {
         try
         {
             writeMolecule(molecules[i]);
         }
         catch (System.Exception exc)
         {
         }
     }
 }
Exemplo n.º 15
0
        // private functions

        /// <summary> Reads a ChemFile object from input.
        ///
        /// </summary>
        /// <returns> ChemFile with the content read from the input
        /// </returns>
        private IChemFile readChemFile(IChemFile cf)
        {
            // have to do stuff here
            try
            {
                System.String line = input.ReadLine();
                while (line != null)
                {
                    if (line.StartsWith("INChI="))
                    {
                        // ok, the fun starts
                        cf = cf.Builder.newChemFile();
                        // ok, we need to parse things like:
                        // INChI=1.12Beta/C6H6/c1-2-4-6-5-3-1/h1-6H
                        //UPGRADE_NOTE: Final was removed from the declaration of 'INChI '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                        System.String          INChI     = line.Substring(6);
                        SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(INChI, "/");
                        // ok, we expect 4 tokens
                        //UPGRADE_NOTE: Final was removed from the declaration of 'version '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                        System.String version = tokenizer.NextToken();                  // 1.12Beta
                        //UPGRADE_NOTE: Final was removed from the declaration of 'formula '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                        System.String formula = tokenizer.NextToken();                  // C6H6
                        //UPGRADE_NOTE: Final was removed from the declaration of 'connections '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                        System.String connections = tokenizer.NextToken().Substring(1); // 1-2-4-6-5-3-1
                        //UPGRADE_NOTE: Final was removed from the declaration of 'hydrogens '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                        System.String hydrogens = tokenizer.NextToken().Substring(1);   // 1-6H

                        IAtomContainer parsedContent = inchiTool.processFormula(cf.Builder.newAtomContainer(), formula);
                        inchiTool.processConnections(connections, parsedContent, -1);

                        ISetOfMolecules moleculeSet = cf.Builder.newSetOfMolecules();
                        moleculeSet.addMolecule(cf.Builder.newMolecule(parsedContent));
                        IChemModel model = cf.Builder.newChemModel();
                        model.SetOfMolecules = moleculeSet;
                        IChemSequence sequence = cf.Builder.newChemSequence();
                        sequence.addChemModel(model);
                        cf.addChemSequence(sequence);
                    }
                    line = input.ReadLine();
                }
            }
            catch (System.Exception 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("Error while reading INChI file: " + exception.Message, exception);
            }
            return(cf);
        }
Exemplo n.º 16
0
        /// <summary>  Description of the Method
        ///
        /// </summary>
        /// <param name="smiles">                     Description of the Parameter
        /// </param>
        /// <returns>                             Description of the Return Value
        /// </returns>
        /// <exception cref="InvalidSmilesException"> Description of the Exception
        /// </exception>
        public virtual Reaction parseReactionSmiles(System.String smiles)
        {
            SupportClass.Tokenizer tokenizer      = new SupportClass.Tokenizer(smiles, ">");
            System.String          reactantSmiles = tokenizer.NextToken();
            System.String          agentSmiles    = "";
            System.String          productSmiles  = tokenizer.NextToken();
            if (tokenizer.HasMoreTokens())
            {
                agentSmiles   = productSmiles;
                productSmiles = tokenizer.NextToken();
            }

            Reaction reaction = new Reaction();

            // add reactants
            IMolecule       reactantContainer = parseSmiles(reactantSmiles);
            ISetOfMolecules reactantSet       = ConnectivityChecker.partitionIntoMolecules(reactantContainer);

            IMolecule[] reactants = reactantSet.Molecules;
            for (int i = 0; i < reactants.Length; i++)
            {
                reaction.addReactant(reactants[i]);
            }

            // add reactants
            if (agentSmiles.Length > 0)
            {
                IMolecule       agentContainer = parseSmiles(agentSmiles);
                ISetOfMolecules agentSet       = ConnectivityChecker.partitionIntoMolecules(agentContainer);
                IMolecule[]     agents         = agentSet.Molecules;
                for (int i = 0; i < agents.Length; i++)
                {
                    reaction.addAgent(agents[i]);
                }
            }

            // add products
            IMolecule       productContainer = parseSmiles(productSmiles);
            ISetOfMolecules productSet       = ConnectivityChecker.partitionIntoMolecules(productContainer);

            IMolecule[] products = productSet.Molecules;
            for (int i = 0; i < products.Length; i++)
            {
                reaction.addProduct(products[i]);
            }

            return(reaction);
        }
Exemplo n.º 17
0
        public static ISetOfMolecules getAllMolecules(IReaction reaction)
        {
            ISetOfMolecules moleculeSet = reaction.Builder.newSetOfMolecules();

            IMolecule[] reactants = reaction.Reactants.Molecules;
            for (int i = 0; i < reactants.Length; i++)
            {
                moleculeSet.addMolecule(reactants[i]);
            }
            IMolecule[] products = reaction.Products.Molecules;
            for (int i = 0; i < products.Length; i++)
            {
                moleculeSet.addMolecule(products[i]);
            }
            return(moleculeSet);
        }
Exemplo n.º 18
0
        private IChemModel readChemModel(IChemModel chemModel)
        {
            ISetOfMolecules setOfMolecules = chemModel.SetOfMolecules;

            if (setOfMolecules == null)
            {
                setOfMolecules = chemModel.Builder.newSetOfMolecules();
            }
            IMolecule m = readMolecule(chemModel.Builder.newMolecule());

            if (m != null)
            {
                setOfMolecules.addMolecule(m);
            }
            chemModel.SetOfMolecules = setOfMolecules;
            return(chemModel);
        }
Exemplo n.º 19
0
        public static IAtomContainer createNewMolecule(IChemModel chemModel)
        {
            // Add a new molecule either the set of molecules
            IMolecule molecule = chemModel.Builder.newMolecule();

            if (chemModel.SetOfMolecules != null)
            {
                ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;
                moleculeSet.addMolecule(molecule);
            }
            else
            {
                ISetOfMolecules moleculeSet = chemModel.Builder.newSetOfMolecules();
                moleculeSet.addMolecule(molecule);
                chemModel.SetOfMolecules = moleculeSet;
            }
            return(molecule);
        }
Exemplo n.º 20
0
        /// <summary> Method that saturates a molecule by adding implicit hydrogens.
        ///
        /// </summary>
        /// <param name="container"> Molecule to saturate
        /// </param>
        /// <cdk.keyword>           hydrogen, adding </cdk.keyword>
        /// <cdk.keyword>           implicit hydrogen </cdk.keyword>
        //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 virtual System.Collections.Hashtable addImplicitHydrogensToSatisfyValency(IAtomContainer container)
        {
            ISetOfMolecules moleculeSet = ConnectivityChecker.partitionIntoMolecules(container);

            IMolecule[] molecules = moleculeSet.Molecules;
            //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'"
            System.Collections.Hashtable hydrogenAtomMap = new System.Collections.Hashtable();
            for (int k = 0; k < molecules.Length; k++)
            {
                IMolecule molPart = molecules[k];
                IAtom[]   atoms   = molPart.Atoms;
                for (int f = 0; f < atoms.Length; f++)
                {
                    int[] hydrogens = addImplicitHydrogensToSatisfyValency(molPart, atoms[f]);
                    hydrogenAtomMap[atoms[f]] = hydrogens;
                }
            }
            return(hydrogenAtomMap);
        }
Exemplo n.º 21
0
 /// <summary> Writes an array of Molecules to an OutputStream in MDL sdf format.
 ///
 /// </summary>
 /// <param name="molecules"> Array of Molecules that is written to an OutputStream
 /// </param>
 private void writeSetOfMolecules(ISetOfMolecules som)
 {
     IMolecule[] molecules = som.Molecules;
     for (int i = 0; i < som.MoleculeCount; i++)
     {
         try
         {
             bool[] isVisible = new bool[molecules[i].AtomCount];
             for (int k = 0; k < isVisible.Length; k++)
             {
                 isVisible[k] = true;
             }
             writeMolecule(molecules[i], isVisible);
         }
         catch (System.Exception exc)
         {
         }
     }
 }
Exemplo n.º 22
0
        /// <summary> Reads partial atomic charges and add the to the given ChemModel.
        ///
        /// </summary>
        /// <param name="model">Description of the Parameter
        /// </param>
        /// <throws>  CDKException Description of the Exception </throws>
        /// <throws>  IOException  Description of the Exception </throws>
        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;
                    if (tokenizer.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                    {
                        charge = 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);
                }
            }
        }
Exemplo n.º 23
0
        /// <summary> Reads data from the "file system" file through the use of the "input"
        /// field, parses data and feeds the ChemFile object with the extracted data.
        ///
        /// </summary>
        /// <returns> A ChemFile containing the data parsed from input.
        ///
        /// </returns>
        /// <throws	IOException	may>  be thrown buy the <code>this.input.readLine()</code> instruction. </throws	IOException	may>
        /// <summary>
        /// </summary>
        /// <seealso cref="org.openscience.cdk.io.GamessReader.input">
        /// </seealso>
        //TODO Answer the question : Is this method's name appropriate (given the fact that it do not read a ChemFile object, but return it)?
        private IChemFile readChemFile(IChemFile file)
        {
            IChemSequence   sequence    = file.Builder.newChemSequence(); // TODO Answer the question : Is this line needed ?
            IChemModel      model       = file.Builder.newChemModel();    // TODO Answer the question : Is this line needed ?
            ISetOfMolecules moleculeSet = file.Builder.newSetOfMolecules();

            model.SetOfMolecules = moleculeSet; //TODO Answer the question : Should I do this?
            sequence.addChemModel(model);       //TODO Answer the question : Should I do this?
            file.addChemSequence(sequence);     //TODO Answer the question : Should I do this?

            System.String currentReadLine = this.input.ReadLine();
            while (this.input.Peek() != -1 == true && (currentReadLine != null))
            {
                /*
                 * There are 2 types of coordinate sets:
                 * - bohr coordinates sets		(if statement)
                 * - angstr???m coordinates sets	(else statement)
                 */
                if (currentReadLine.IndexOf("COORDINATES (BOHR)") >= 0)
                {
                    /*
                     * The following line do no contain data, so it is ignored.
                     */
                    this.input.ReadLine();
                    moleculeSet.addMolecule(this.readCoordinates(file.Builder.newMolecule(), GamessReader.BOHR_UNIT));
                    //break; //<- stops when the first set of coordinates is found.
                }
                else if (currentReadLine.IndexOf(" COORDINATES OF ALL ATOMS ARE (ANGS)") >= 0)
                {
                    /*
                     * The following 2 lines do no contain data, so it are ignored.
                     */
                    this.input.ReadLine();
                    this.input.ReadLine();

                    moleculeSet.addMolecule(this.readCoordinates(file.Builder.newMolecule(), GamessReader.ANGSTROM_UNIT));
                    //break; //<- stops when the first set of coordinates is found.
                }
                currentReadLine = this.input.ReadLine();
            }
            return(file);
        }
Exemplo n.º 24
0
        public static IAtomContainer getRelevantAtomContainer(IChemModel chemModel, IBond bond)
        {
            IAtomContainer result = null;

            if (chemModel.SetOfMolecules != null)
            {
                ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;
                result = SetOfMoleculesManipulator.getRelevantAtomContainer(moleculeSet, bond);
                if (result != null)
                {
                    return(result);
                }
            }
            if (chemModel.SetOfReactions != null)
            {
                ISetOfReactions reactionSet = chemModel.SetOfReactions;
                return(SetOfReactionsManipulator.getRelevantAtomContainer(reactionSet, bond));
            }
            // This should never happen.
            return(null);
        }
Exemplo n.º 25
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);
            }
        }
Exemplo n.º 26
0
        /// <summary> Method that saturates a molecule by adding explicit hydrogens.
        /// In order to get coordinates for these Hydrogens, you need to
        /// remember the average bondlength of you molecule (coordinates for
        /// all atoms should be available) by using
        /// double bondLength = GeometryTools.getBondLengthAverage(atomContainer);
        /// and then use this method here and then use
        /// org.openscience.cdk.HydrogenPlacer(atomContainer, bondLength);
        ///
        /// </summary>
        /// <param name="molecule"> Molecule to saturate
        /// </param>
        /// <cdk.keyword>           hydrogen, adding </cdk.keyword>
        /// <cdk.keyword>           explicit hydrogen </cdk.keyword>
        public virtual IAtomContainer addExplicitHydrogensToSatisfyValency(IMolecule molecule)
        {
            //logger.debug("Start of addExplicitHydrogensToSatisfyValency");
            ISetOfMolecules moleculeSet = ConnectivityChecker.partitionIntoMolecules(molecule);

            IMolecule[]    molecules             = moleculeSet.Molecules;
            IAtomContainer changedAtomsAndBonds  = molecule.Builder.newAtomContainer();
            IAtomContainer intermediateContainer = null;

            for (int k = 0; k < molecules.Length; k++)
            {
                IMolecule molPart = molecules[k];
                IAtom[]   atoms   = molPart.Atoms;
                for (int i = 0; i < atoms.Length; i++)
                {
                    intermediateContainer = addHydrogensToSatisfyValency(molPart, atoms[i], molecule);
                    changedAtomsAndBonds.add(intermediateContainer);
                }
            }
            //logger.debug("End of addExplicitHydrogensToSatisfyValency");
            return(changedAtomsAndBonds);
        }
Exemplo n.º 27
0
        public static int getBondCount(IChemModel chemModel)
        {
            int      count   = 0;
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                count += crystal.getBondCount();
            }
            ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;

            if (moleculeSet != null)
            {
                count += SetOfMoleculesManipulator.getBondCount(moleculeSet);
            }
            ISetOfReactions reactionSet = chemModel.SetOfReactions;

            if (reactionSet != null)
            {
                count += SetOfReactionsManipulator.getBondCount(reactionSet);
            }
            return(count);
        }
Exemplo n.º 28
0
        /// <summary> Puts all the Molecules of this container together in one
        /// AtomContainer.
        ///
        /// </summary>
        /// <returns>  The AtomContainer with all the Molecules of this container
        ///
        /// </returns>
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(IChemModel chemModel)
        {
            IAtomContainer container = chemModel.Builder.newAtomContainer();
            ICrystal       crystal   = chemModel.Crystal;

            if (crystal != null)
            {
                container.add(crystal);
            }
            ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;

            if (moleculeSet != null)
            {
                container.add(SetOfMoleculesManipulator.getAllInOneContainer(moleculeSet));
            }
            ISetOfReactions reactionSet = chemModel.SetOfReactions;

            if (reactionSet != null)
            {
                container.add(SetOfReactionsManipulator.getAllInOneContainer(reactionSet));
            }
            return(container);
        }
Exemplo n.º 29
0
        public static System.Collections.IList getAllChemObjects(IChemModel chemModel)
        {
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            list.Add(chemModel);
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                list.Add(crystal);
            }
            ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;

            if (moleculeSet != null)
            {
                list.AddRange(SetOfMoleculesManipulator.getAllChemObjects(moleculeSet));
            }
            ISetOfReactions reactionSet = chemModel.SetOfReactions;

            if (reactionSet != null)
            {
                list.AddRange(SetOfReactionsManipulator.getAllChemObjects(reactionSet));
            }
            return(list);
        }
Exemplo n.º 30
0
 /// <summary>  Returns the minimum and maximum X and Y coordinates of the molecules in the
 /// SetOfMolecules. The output is returned as: <pre>
 /// minmax[0] = minX;
 /// minmax[1] = minY;
 /// minmax[2] = maxX;
 /// minmax[3] = maxY;
 /// </pre>
 /// See comment for center(ISetOfMolecules setOfMolecules, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets
 /// 
 /// </summary>
 /// <returns>            An four int array as defined above.
 /// </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 double[] getMinMax(ISetOfMolecules setOfMolecules, System.Collections.Hashtable renderingCoordinates)
 {
     //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Double.MIN_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
     double maxX = System.Double.MinValue;
     //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Double.MIN_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
     double maxY = System.Double.MinValue;
     //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Double.MAX_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
     double minX = System.Double.MaxValue;
     //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Double.MAX_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
     double minY = System.Double.MaxValue;
     for (int j = 0; j < setOfMolecules.AtomContainerCount; j++)
     {
         IAtomContainer container = setOfMolecules.getAtomContainer(j);
         for (int i = 0; i < container.AtomCount; i++)
         {
             IAtom atom = container.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[atom] != 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'"
                 if (((Point2d)renderingCoordinates[atom]).x > maxX)
                 {
                     //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'"
                     maxX = ((Point2d)renderingCoordinates[atom]).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'"
                 if (((Point2d)renderingCoordinates[atom]).x < minX)
                 {
                     //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'"
                     minX = ((Point2d)renderingCoordinates[atom]).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'"
                 if (((Point2d)renderingCoordinates[atom]).y > maxY)
                 {
                     //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'"
                     maxY = ((Point2d)renderingCoordinates[atom]).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 (((Point2d)renderingCoordinates[atom]).y < minY)
                 {
                     //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'"
                     minY = ((Point2d)renderingCoordinates[atom]).y;
                 }
             }
         }
     }
     double[] minmax = new double[4];
     minmax[0] = minX;
     minmax[1] = minY;
     minmax[2] = maxX;
     minmax[3] = maxY;
     return minmax;
 }
Exemplo n.º 31
0
 /// <summary>  Returns the java.awt.Dimension of a SetOfMolecules
 /// See comment for center(ISetOfMolecules setOfMolecules, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets
 /// 
 /// </summary>
 /// <param name="setOfMolecules">Of which the dimension should be returned
 /// </param>
 /// <returns> The java.awt.Dimension of this SetOfMolecules
 /// </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 System.Drawing.Size get2DDimension(ISetOfMolecules setOfMolecules, System.Collections.Hashtable renderingCoordinates)
 {
     double[] minmax = getMinMax(setOfMolecules, renderingCoordinates);
     double maxX = minmax[2];
     double maxY = minmax[3];
     double minX = minmax[0];
     double minY = minmax[1];
     //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'"
     return new System.Drawing.Size((int)(maxX - minX + 1), (int)(maxY - minY + 1));
 }
Exemplo n.º 32
0
        /// <summary> Writes a SetOfMolecules to an OutputStream for the reaction.
        /// 
        /// </summary>
        /// <param name="som"> The SetOfMolecules that is written to an OutputStream 
        /// </param>
        private void writeSetOfMolecules(ISetOfMolecules som)
        {

            for (int i = 0; i < som.MoleculeCount; i++)
            {
                IMolecule mol = som.getMolecule(i);
                for (int j = 0; j < som.getMultiplier(i); j++)
                {
                    //MemoryStream ms = new MemoryStream();
                    //StreamWriter sw = new StreamWriter(ms);
                    writer.Write("$MOL\n");
                    MDLWriter mdlwriter = null;
                    try
                    {
                        mdlwriter = new MDLWriter(writer);
                    }
                    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 creating MDLWriter: " + ex.Message, ex);
                    }
                    mdlwriter.write(mol);
                    //writer.Write(sw.ToString());
                }
            }
        }
Exemplo n.º 33
0
 /// <summary>  Adds all molecules in the SetOfMolecules to this container.
 /// 
 /// </summary>
 /// <param name="moleculeSet"> The SetOfMolecules 
 /// </param>
 public virtual void add(ISetOfMolecules moleculeSet)
 {
     IMolecule[] mols = moleculeSet.Molecules;
     for (int i = 0; i < mols.Length; i++)
     {
         addMolecule(mols[i]);
     }
     /* notifyChanged() called in super.addAtomContainer() */
 }
Exemplo n.º 34
0
 /// <summary> Constructs an empty, forward reaction.</summary>
 public Reaction()
 {
     this.reactants = new SetOfMolecules();
     this.products = new SetOfMolecules();
     this.agents = new SetOfMolecules();
     this.map = new Mapping[growArraySize];
     mappingCount = 0;
     reactionDirection = IReaction_Fields.FORWARD;
 }
Exemplo n.º 35
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);
        }
Exemplo n.º 36
0
        /// <summary> writes all the molecules supplied in a SetOfMolecules class to
        /// a single HIN file. You can also supply a single Molecule object
        /// as well
        /// </summary>
        /// <param name="mol">the Molecule to write
        /// </param>
        private void writeMolecule(ISetOfMolecules som)
        {

            //int na = 0;
            //String info = "";
            System.String sym = "";
            double chrg = 0.0;
            //boolean writecharge = true;

            for (int molnum = 0; molnum < som.MoleculeCount; molnum++)
            {

                IMolecule mol = som.getMolecule(molnum);

                try
                {

                    int natom = mol.AtomCount;
                    int nbond = mol.getBondCount();

                    System.String molname = "mol " + (molnum + 1) + " " + ((System.String)mol.getProperty(CDKConstants.TITLE));

                    //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                    writer.Write(molname.ToCharArray(), 0, molname.Length);
                    //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                    writer.WriteLine();

                    // Loop through the atoms and write them out:
                    IAtom[] atoms = mol.Atoms;
                    IBond[] bonds = mol.Bonds;

                    for (int i = 0; i < natom; i++)
                    {

                        System.String line = "atom ";
                        IAtom a = atoms[i];

                        sym = a.Symbol;
                        chrg = a.getCharge();
                        Point3d p3 = a.getPoint3d();

                        line = line + ((System.Int32)(i + 1)).ToString() + " - " + sym + " ** - " + ((double)chrg).ToString() + " " + p3.x.ToString() + " " + p3.y.ToString() + " " + p3.z.ToString() + " ";

                        System.String buf = "";
                        int ncon = 0;
                        for (int j = 0; j < nbond; j++)
                        {
                            IBond b = bonds[j];
                            if (b.contains(a))
                            {
                                // current atom is in the bond so lets get the connected atom
                                IAtom ca = b.getConnectedAtom(a);
                                double bo = b.Order;
                                int serial = -1;
                                System.String bt = "";

                                // get the serial no for this atom
                                serial = mol.getAtomNumber(ca);

                                if (bo == 1)
                                    bt = new System.Text.StringBuilder("s").ToString();
                                else if (bo == 2)
                                    bt = new System.Text.StringBuilder("d").ToString();
                                else if (bo == 3)
                                    bt = new System.Text.StringBuilder("t").ToString();
                                else if (bo == 1.5)
                                    bt = new System.Text.StringBuilder("a").ToString();
                                buf = buf + ((System.Int32)(serial + 1)).ToString() + " " + bt + " ";
                                ncon++;
                            }
                        }
                        line = line + " " + ((System.Int32)ncon).ToString() + " " + buf;
                        //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                        writer.Write(line.ToCharArray(), 0, line.Length);
                        //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                        writer.WriteLine();
                    }
                    System.String buf2 = "endmol " + (molnum + 1);
                    //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                    writer.Write(buf2.ToCharArray(), 0, buf2.Length);
                    //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                    writer.WriteLine();
                }
                catch (System.IO.IOException e)
                {
                    throw e;
                }
            }
        }
Exemplo n.º 37
0
 /// <summary> Writes a list of molecules to an OutputStream
 /// 
 /// </summary>
 /// <param name="som"> SetOfMolecules that is written to an OutputStream
 /// </param>
 public virtual void writeSetOfMolecules(ISetOfMolecules som)
 {
     IMolecule[] molecules = som.Molecules;
     writeMolecule(molecules[0]);
     for (int i = 1; i <= som.MoleculeCount - 1; i++)
     {
         try
         {
             writeMolecule(molecules[i]);
         }
         catch (System.Exception exc)
         {
         }
     }
 }
Exemplo n.º 38
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());
        }
Exemplo n.º 39
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());
        }
Exemplo n.º 40
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();
     }
 }
Exemplo n.º 41
0
 public virtual void createIDs(ISetOfMolecules containerSet)
 {
     createIDs((ISetOfAtomContainers)containerSet);
 }
Exemplo n.º 42
0
 /// <summary> Writes an array of Molecules to an OutputStream in MDL sdf format.
 /// 
 /// </summary>
 /// <param name="molecules"> Array of Molecules that is written to an OutputStream 
 /// </param>
 private void writeSetOfMolecules(ISetOfMolecules som)
 {
     IMolecule[] molecules = som.Molecules;
     for (int i = 0; i < som.MoleculeCount; i++)
     {
         try
         {
             bool[] isVisible = new bool[molecules[i].AtomCount];
             for (int k = 0; k < isVisible.Length; k++)
             {
                 isVisible[k] = true;
             }
             writeMolecule(molecules[i], isVisible);
         }
         catch (System.Exception exc)
         {
         }
     }
 }