示例#1
0
        /// <summary> Adds a product to this reaction.
        ///
        /// </summary>
        /// <param name="product">    Molecule added as product to this reaction
        /// </param>
        /// <param name="coefficient">Stoichiometry coefficient for this molecule
        /// </param>
        /// <seealso cref="getProducts">
        /// </seealso>
        public virtual void addProduct(IMolecule product, double coefficient)
        {
            products.addAtomContainer(product, coefficient);

            /* notifyChanged() is called by
             * addReactant(Molecule reactant, double coefficient) */
        }
        public static IChemModel newChemModel(IAtomContainer molecule)
        {
            IChemModel      model       = molecule.Builder.newChemModel();
            ISetOfMolecules moleculeSet = model.Builder.newSetOfMolecules();

            moleculeSet.addAtomContainer(molecule);
            model.SetOfMolecules = moleculeSet;
            return(model);
        }
示例#3
0
        /// <summary> Read a <code>ChemFile</code> from a file in PDB format. The molecules
        /// in the file are stored as <code>BioPolymer</code>s in the
        /// <code>ChemFile</code>. The residues are the monomers of the
        /// <code>BioPolymer</code>, and their names are the concatenation of the
        /// residue, chain id, and the sequence number. Separate chains (denoted by
        /// TER records) are stored as separate <code>BioPolymer</code> molecules.
        ///
        /// <p>Connectivity information is not currently read.
        ///
        /// </summary>
        /// <returns> The ChemFile that was read from the PDB file.
        /// </returns>
        private IChemFile readChemFile(IChemFile oFile)
        {
            int bonds = 0;
            // initialize all containers
            IChemSequence   oSeq   = oFile.Builder.newChemSequence();
            IChemModel      oModel = oFile.Builder.newChemModel();
            ISetOfMolecules oSet   = oFile.Builder.newSetOfMolecules();

            // some variables needed
            string     cCol;
            PDBAtom    oAtom;
            PDBPolymer oBP = new PDBPolymer();

            System.Text.StringBuilder cResidue;
            string   oObj;
            IMonomer oMonomer;
            string   cRead = "";
            char     chain = 'A'; // To ensure stringent name giving of monomers
            IStrand  oStrand;
            int      lineLength = 0;

            atomNumberMap = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());

            // do the reading of the Input
            try
            {
                do
                {
                    cRead = _oInput.ReadLine();
                    //logger.debug("Read line: ", cRead);
                    if (cRead != null)
                    {
                        lineLength = cRead.Length;

                        if (lineLength < 80)
                        {
                            //logger.warn("Line is not of the expected length 80!");
                        }

                        // make sure the record name is 6 characters long
                        if (lineLength < 6)
                        {
                            cRead = cRead + "      ";
                        }
                        // check the first column to decide what to do
                        cCol = cRead.Substring(0, (6) - (0));
                        if ("ATOM  ".ToUpper().Equals(cCol.ToUpper()))
                        {
                            // read an atom record
                            oAtom = readAtom(cRead, lineLength);

                            // construct a string describing the residue
                            cResidue = new System.Text.StringBuilder(8);
                            oObj     = oAtom.ResName;
                            if (oObj != null)
                            {
                                cResidue = cResidue.Append(oObj.Trim());
                            }
                            oObj = oAtom.ChainID;
                            if (oObj != null)
                            {
                                // cResidue = cResidue.append(((String)oObj).trim());
                                cResidue = cResidue.Append(System.Convert.ToString(chain));
                            }
                            oObj = oAtom.ResSeq;
                            if (oObj != null)
                            {
                                cResidue = cResidue.Append(oObj.Trim());
                            }

                            // search for an existing strand or create a new one.
                            oStrand = oBP.getStrand(System.Convert.ToString(chain));
                            if (oStrand == null)
                            {
                                oStrand            = new PDBStrand();
                                oStrand.StrandName = System.Convert.ToString(chain);
                            }

                            // search for an existing monomer or create a new one.
                            oMonomer = oBP.getMonomer(cResidue.ToString(), System.Convert.ToString(chain));
                            if (oMonomer == null)
                            {
                                PDBMonomer monomer = new PDBMonomer();
                                monomer.MonomerName = cResidue.ToString();
                                monomer.MonomerType = oAtom.ResName;
                                monomer.ChainID     = oAtom.ChainID;
                                monomer.ICode       = oAtom.ICode;
                                oMonomer            = monomer;
                            }

                            // add the atom
                            oBP.addAtom(oAtom, oMonomer, oStrand);
                            System.Object tempObject;
                            //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
                            tempObject = atomNumberMap[(System.Int32)oAtom.Serial];
                            atomNumberMap[(System.Int32)oAtom.Serial] = oAtom;
                            if (readConnect.Set && tempObject != null)
                            {
                                //logger.warn("Duplicate serial ID found for atom: ", oAtom);
                            }
                            //						//logger.debug("Added ATOM: ", oAtom);

                            /** As HETATMs cannot be considered to either belong to a certain monomer or strand,
                             * they are dealt with seperately.*/
                        }
                        else if ("HETATM".ToUpper().Equals(cCol.ToUpper()))
                        {
                            // read an atom record
                            oAtom         = readAtom(cRead, lineLength);
                            oAtom.HetAtom = true;
                            oBP.addAtom(oAtom);
                            System.Object tempObject2;
                            //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
                            tempObject2 = atomNumberMap[(System.Int32)oAtom.Serial];
                            atomNumberMap[(System.Int32)oAtom.Serial] = oAtom;
                            if (tempObject2 != null)
                            {
                                //logger.warn("Duplicate serial ID found for atom: ", oAtom);
                            }
                            //logger.debug("Added HETATM: ", oAtom);
                        }
                        else if ("TER   ".ToUpper().Equals(cCol.ToUpper()))
                        {
                            // start new strand
                            chain++;
                            oStrand            = new PDBStrand();
                            oStrand.StrandName = System.Convert.ToString(chain);
                            //logger.debug("Added new STRAND");
                        }
                        else if ("END   ".ToUpper().Equals(cCol.ToUpper()))
                        {
                            atomNumberMap.Clear();
                            // create bonds and finish the molecule
                            if (deduceBonding.Set)
                            {
                                // OK, try to deduce the bonding patterns
                                if (oBP.AtomCount != 0)
                                {
                                    // Create bonds. If bonds could not be created, all bonds are deleted.
                                    try
                                    {
                                        if (useRebondTool.Set)
                                        {
                                            if (!createBondsWithRebondTool(oBP))
                                            {
                                                // Get rid of all potentially created bonds.
                                                //logger.info("Bonds could not be created using the RebondTool when PDB file was read.");
                                                oBP.removeAllBonds();
                                            }
                                        }
                                        else
                                        {
                                            if (!createBonds(oBP))
                                            {
                                                // Get rid of all potentially created bonds.
                                                //logger.info("Bonds could not be created when PDB file was read.");
                                                oBP.removeAllBonds();
                                            }
                                        }
                                    }
                                    catch (System.Exception exception)
                                    {
                                        //logger.info("Bonds could not be created when PDB file was read.");
                                        //logger.debug(exception);
                                    }
                                }
                            }
                            oSet.addMolecule(oBP);
                            //						oBP = new BioPolymer();
                            //				} else if (cCol.equals("USER  ")) {
                            //						System.out.println(cLine);
                            //					System.out.println(cLine);
                            //				} else if (cCol.equals("ENDMDL")) {
                            //					System.out.println(cLine);
                        }
                        else if (cCol.Equals("MODEL "))
                        {
                            // OK, start a new model and save the current one first *if* it contains atoms
                            if (oBP.AtomCount > 0)
                            {
                                // save the model
                                oSet.addAtomContainer(oBP);
                                oModel.SetOfMolecules = oSet;
                                oSeq.addChemModel(oModel);
                                // setup a new one
                                oBP    = new PDBPolymer();
                                oModel = oFile.Builder.newChemModel();
                                oSet   = oFile.Builder.newSetOfMolecules();
                            }
                        }
                        else if ("REMARK".ToUpper().Equals(cCol.ToUpper()))
                        {
                            System.Object comment = oFile.getProperty(CDKConstants.COMMENT);
                            if (comment == null)
                            {
                                comment = "";
                            }
                            if (lineLength > 12)
                            {
                                //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'"
                                comment = comment.ToString() + cRead.Substring(11).Trim() + "\n";
                                oFile.setProperty(CDKConstants.COMMENT, comment);
                            }
                            else
                            {
                                //logger.warn("REMARK line found without any comment!");
                            }
                        }
                        else if ("COMPND".ToUpper().Equals(cCol.ToUpper()))
                        {
                            string title = cRead.Substring(10).Trim();
                            oFile.setProperty(CDKConstants.TITLE, title);
                        }

                        /*************************************************************
                         * Read connectivity information from CONECT records.
                         * Only covalent bonds are dealt with. Perhaps salt bridges
                         * should be dealt with in the same way..?
                         */
                        else if (readConnect.Set && "CONECT".ToUpper().Equals(cCol.ToUpper()))
                        {
                            cRead.Trim();
                            if (cRead.Length < 16)
                            {
                                //logger.debug("Skipping unexpected empty CONECT line! : ", cRead);
                            }
                            else
                            {
                                string bondAtom   = cRead.Substring(7, 5).Trim();
                                int    bondAtomNo = System.Int32.Parse(bondAtom);

                                for (int b = 0; b < 9; b += (b == 5 ? 2 : 1))
                                {
                                    string bondedAtom = cRead.Substring((b * 5) + 11, 5).Trim();
                                    int    bondedAtomNo;
                                    if (int.TryParse(bondedAtom, out bondedAtomNo))
                                    {
                                        bonds++;
                                        addBond(oBP, bondAtomNo, bondedAtomNo);
                                    }
                                }

                                //string bondedAtom = cRead.Substring(12, 5).Trim();
                                //int bondedAtomNo = -1;

                                //try
                                //{
                                //    bondedAtomNo = System.Int32.Parse(bondedAtom);
                                //}
                                //catch (System.Exception e)
                                //{
                                //    bondedAtomNo = -1;
                                //}

                                //if (bondedAtomNo != -1)
                                //{
                                //    bonds++;
                                //    addBond(oBP, bondAtomNo, bondedAtomNo);
                                //    //logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo);
                                //}
                                //else
                                //{
                                //}

                                //if (cRead.Length > 17)
                                //{
                                //    bondedAtom = cRead.Substring(16, 5);
                                //    bondedAtom = bondedAtom.Trim();
                                //    try
                                //    {
                                //        bondedAtomNo = System.Int32.Parse(bondedAtom);
                                //    }
                                //    catch (System.Exception e)
                                //    {
                                //        bondedAtomNo = -1;
                                //    }

                                //    if (bondedAtomNo != -1)
                                //    {
                                //        bonds++;
                                //        addBond(oBP, bondAtomNo, bondedAtomNo);
                                //        //logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo);
                                //    }
                                //}

                                //if (cRead.Length > 22)
                                //{
                                //    bondedAtom = cRead.Substring(22, 5);
                                //    bondedAtom = bondedAtom.Trim();
                                //    try
                                //    {
                                //        bondedAtomNo = System.Int32.Parse(bondedAtom);
                                //    }
                                //    catch (System.Exception e)
                                //    {
                                //        bondedAtomNo = -1;
                                //    }

                                //    if (bondedAtomNo != -1)
                                //    {
                                //        bonds++;
                                //        addBond(oBP, bondAtomNo, bondedAtomNo);
                                //        //logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo);
                                //    }
                                //}

                                //if (cRead.Length > 27)
                                //{
                                //    bondedAtom = cRead.Substring(27, 5);
                                //    bondedAtom = bondedAtom.Trim();
                                //    try
                                //    {
                                //        bondedAtomNo = System.Int32.Parse(bondedAtom);
                                //    }
                                //    catch (System.Exception e)
                                //    {
                                //        bondedAtomNo = -1;
                                //    }

                                //    if (bondedAtomNo != -1)
                                //    {
                                //        bonds++;
                                //        addBond(oBP, bondAtomNo, bondedAtomNo);
                                //        //logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo);
                                //    }
                                //}
                            }
                        }
                        /*************************************************************/
                        else if ("HELIX ".ToUpper().Equals(cCol.ToUpper()))
                        {
                            //						HELIX    1 H1A CYS A   11  LYS A   18  1 RESIDUE 18 HAS POSITIVE PHI    1D66  72
                            //						          1         2         3         4         5         6         7
                            //						01234567890123456789012345678901234567890123456789012345678901234567890123456789
                            PDBStructure structure = new PDBStructure();
                            structure.StructureType       = PDBStructure.HELIX;
                            structure.StartChainID        = cRead[19];
                            structure.StartSequenceNumber = System.Int32.Parse(cRead.Substring(21, (25) - (21)).Trim());
                            structure.StartInsertionCode  = cRead[25];
                            structure.EndChainID          = cRead[31];
                            structure.EndSequenceNumber   = System.Int32.Parse(cRead.Substring(33, (37) - (33)).Trim());
                            structure.EndInsertionCode    = cRead[37];
                            oBP.addStructure(structure);
                        }
                        else if ("SHEET ".ToUpper().Equals(cCol.ToUpper()))
                        {
                            PDBStructure structure = new PDBStructure();
                            structure.StructureType       = PDBStructure.SHEET;
                            structure.StartChainID        = cRead[21];
                            structure.StartSequenceNumber = System.Int32.Parse(cRead.Substring(22, (26) - (22)).Trim());
                            structure.StartInsertionCode  = cRead[26];
                            structure.EndChainID          = cRead[32];
                            structure.EndSequenceNumber   = System.Int32.Parse(cRead.Substring(33, (37) - (33)).Trim());
                            structure.EndInsertionCode    = cRead[37];
                            oBP.addStructure(structure);
                        }
                        else if ("TURN  ".ToUpper().Equals(cCol.ToUpper()))
                        {
                            PDBStructure structure = new PDBStructure();
                            structure.StructureType       = PDBStructure.TURN;
                            structure.StartChainID        = cRead[19];
                            structure.StartSequenceNumber = System.Int32.Parse(cRead.Substring(20, (24) - (20)).Trim());
                            structure.StartInsertionCode  = cRead[24];
                            structure.EndChainID          = cRead[30];
                            structure.EndSequenceNumber   = System.Int32.Parse(cRead.Substring(31, (35) - (31)).Trim());
                            structure.EndInsertionCode    = cRead[35];
                            oBP.addStructure(structure);
                        } // ignore all other commands
                    }
                }while (_oInput.Peek() != -1 && (cRead != null));
            }
            catch (System.Exception e)
            {
                //logger.error("Found a problem at line:\n");
                //logger.error(cRead);
                //logger.error("01234567890123456789012345678901234567890123456789012345678901234567890123456789");
                //logger.error("          1         2         3         4         5         6         7         ");
                //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("  error: " + e.Message);
                //logger.debug(e);
            }

            // try to close the Input
            try
            {
                _oInput.Close();
            }
            catch (System.Exception e)
            {
                //logger.debug(e);
            }

            // Set all the dependencies
            oModel.SetOfMolecules = oSet;
            oSeq.addChemModel(oModel);
            oFile.addChemSequence(oSeq);

            return(oFile);
        }
示例#4
0
 /// <summary> Adds a reactant to this reaction with a stoichiometry coefficient.
 ///
 /// </summary>
 /// <param name="reactant">   Molecule added as reactant to this reaction
 /// </param>
 /// <param name="coefficient">Stoichiometry coefficient for this molecule
 /// </param>
 /// <seealso cref="getReactants">
 /// </seealso>
 public virtual void addReactant(IMolecule reactant, double coefficient)
 {
     reactants.addAtomContainer(reactant, coefficient);
     notifyChanged();
 }
示例#5
0
 /// <summary> Adds an agent to this reaction.
 ///
 /// </summary>
 /// <param name="agent">  Molecule added as agent to this reaction
 /// </param>
 /// <seealso cref="getAgents">
 /// </seealso>
 public virtual void addAgent(IMolecule agent)
 {
     agents.addAtomContainer(agent);
     notifyChanged();
 }