コード例 #1
0
ファイル: Chain.cs プロジェクト: prabuddha1987/NuGenBioChem
        void UpdateVisualModel()
        {
            Children.Clear();
            residues.Clear();

            this.Ribbon = new Ribbon(this);
            if (this.Ribbon.IsSuccessful)
            {
                foreach (var residueData in this.data.Residues)
                {
                    Residue visualResidue = new Residue();
                    this.residues.Add(visualResidue, residueData);
                    visualResidue.Chain = this;
                    visualResidue.Style = style;
                    Children.Add(visualResidue);
                }
            }

            UpdateMaterials();
        }
コード例 #2
0
ファイル: Chain.cs プロジェクト: prabuddha1987/NuGenBioChem
 /// <summary>
 /// Gets the data of the given residue
 /// </summary>
 /// <param name="residue">Residue</param>
 /// <returns>Residue data</returns>
 public Data.Residue GetResidueData(Residue residue)
 {
     Data.Residue result;
     return this.residues.TryGetValue(residue, out result) ? result : null;
 }
コード例 #3
0
        /// <summary>
        /// Add parsing of elements in mdmolecule:
        /// <list type="bullet">
        ///   <item>mdmolecule</item>
        ///   <list type="bullet">
        ///     <item>chargeGroup</item>
        ///     <list type="bullet">
        ///       <item>id</item>
        ///       <item>cgNumber</item>
        ///       <item>atomArray</item>
        ///       <item>switchingAtom</item>
        ///     </list>
        ///   </list>
        ///   <item>residue</item>
        ///   <list type="bullet">
        ///     <item>id</item>
        ///     <item>title</item>
        ///     <item>resNumber</item>
        ///     <item>atomArray</item>
        ///   </list>
        /// </list>
        /// </summary>
        /// <param name="xpath"></param>
        /// <param name="element"></param>
        // @cdk.todo The JavaDoc of this class needs to be converted into HTML
        public override void StartElement(CMLStack xpath, XElement element)
        {
            // <molecule convention="md:mdMolecule"
            //              xmlns="http://www.xml-cml.org/schema"
            //              xmlns:md="http://www.bioclipse.org/mdmolecule">
            //      <atomArray>
            //        <atom id="a1" elementType="C"/>
            //        <atom id="a2" elementType="C"/>
            //      </atomArray>
            //      <molecule dictRef="md:chargeGroup" id="cg1">
            //        <scalar dictRef="md:cgNumber">5</scalar>
            //        <atomArray>
            //          <atom ref="a1"/>
            //          <atom ref="a2"><scalar dictRef="md:switchingAtom"/></atom>
            //        </atomArray>
            //      </molecule>
            //      <molecule dictRef="md:residue" id="r1" title="resName">
            //        <scalar dictRef="md:resNumber">3</scalar>
            //        <atomArray>
            //          <atom ref="a1"/>
            //          <atom ref="a2"/>
            //        </atomArray>
            //      </molecule>
            //    </molecule>

            // let the CMLCore convention deal with things first

            if (element.Name == XName_CML_molecule)
            {
                // the copy the parsed content into a new MDMolecule
                if (element.Attribute(Attribute_convention) != null && string.Equals(element.Attribute(Attribute_convention).Value, "md:mdMolecule", StringComparison.Ordinal))
                {
                    base.StartElement(xpath, element);
                    CurrentMolecule = new MDMolecule(CurrentMolecule);
                }
                else
                {
                    DictRef = element.Attribute(Attribute_dictRef) != null?element.Attribute(Attribute_dictRef).Value : "";

                    //If residue or chargeGroup, set up a new one
                    switch (DictRef)
                    {
                    case "md:chargeGroup":
                        currentChargeGroup = new ChargeGroup();
                        break;

                    case "md:residue":
                        currentResidue = new Residue();
                        if (element.Attribute(Attribute_title) != null)
                        {
                            currentResidue.Name = element.Attribute(Attribute_title).Value;
                        }
                        break;
                    }
                }
            }
            else
            //We have a scalar element. Now check who it belongs to
            if (element.Name == XName_CML_scalar)
            {
                DictRef = element.Attribute(Attribute_dictRef).Value;
                //Switching Atom
                switch (DictRef)
                {
                case "md:switchingAtom":
                    //Set current atom as switching atom
                    currentChargeGroup.SetSwitchingAtom(CurrentAtom);
                    break;

                default:
                    base.StartElement(xpath, element);
                    break;
                }
            }
            else if (element.Name == XName_CML_atom)
            {
                if (currentChargeGroup != null)
                {
                    string id = element.Attribute(Attribute_ref).Value;
                    if (id != null)
                    {
                        // ok, an atom is referenced; look it up
                        CurrentAtom = null;
                        foreach (var nextAtom in CurrentMolecule.Atoms)
                        {
                            if (string.Equals(nextAtom.Id, id, StringComparison.Ordinal))
                            {
                                CurrentAtom = nextAtom;
                            }
                        }
                        if (CurrentAtom == null)
                        {
                            Trace.TraceError($"Could not found the referenced atom '{id}' for this charge group!");
                        }
                        else
                        {
                            currentChargeGroup.Atoms.Add(CurrentAtom);
                        }
                    }
                }
                else if (currentResidue != null)
                {
                    string id = element.Attribute(Attribute_ref).Value;
                    if (id != null)
                    {
                        // ok, an atom is referenced; look it up
                        IAtom referencedAtom = null;
                        foreach (var nextAtom in CurrentMolecule.Atoms)
                        {
                            if (string.Equals(nextAtom.Id, id, StringComparison.Ordinal))
                            {
                                referencedAtom = nextAtom;
                            }
                        }
                        if (referencedAtom == null)
                        {
                            Trace.TraceError($"Could not found the referenced atom '{id}' for this residue!");
                        }
                        else
                        {
                            currentResidue.Atoms.Add(referencedAtom);
                        }
                    }
                }
                else
                {
                    // ok, fine, just add it to the currentMolecule
                    base.StartElement(xpath, element);
                }
            }
            else
            {
                base.StartElement(xpath, element);
            }
        }
コード例 #4
0
        /// <summary>
        /// Finish up parsing of elements in mdmolecule.
        /// </summary>
        /// <param name="xpath"></param>
        /// <param name="element"></param>
        public override void EndElement(CMLStack xpath, XElement element)
        {
            if (element.Name.Equals(XName_CML_molecule))
            {
                // add chargeGroup, and then delete them
                if (currentChargeGroup != null)
                {
                    if (CurrentMolecule is MDMolecule)
                    {
                        ((MDMolecule)CurrentMolecule).AddChargeGroup(currentChargeGroup);
                    }
                    else
                    {
                        Trace.TraceError("Need to store a charge group, but the current molecule is not a MDMolecule!");
                    }
                    currentChargeGroup = null;
                }
                else

                // add chargeGroup, and then delete them
                if (currentResidue != null)
                {
                    if (CurrentMolecule is MDMolecule)
                    {
                        ((MDMolecule)CurrentMolecule).AddResidue(currentResidue);
                    }
                    else
                    {
                        Trace.TraceError("Need to store a residue group, but the current molecule is not a MDMolecule!");
                    }
                    currentResidue = null;
                }
                else
                {
                    base.EndElement(xpath, element);
                }
            }
            else if (element.Name == XName_CML_atomArray)
            {
                if (xpath.Count == 2 && xpath.EndsWith("molecule", "atomArray"))
                {
                    StoreAtomData();
                    NewAtomData();
                }
                else if (xpath.Count > 2 && xpath.EndsWith("cml", "molecule", "atomArray"))
                {
                    StoreAtomData();
                    NewAtomData();
                }
            }
            else if (element.Name == XName_CML_bondArray)
            {
                if (xpath.Count == 2 && xpath.EndsWith("molecule", "bondArray"))
                {
                    StoreBondData();
                    NewBondData();
                }
                else if (xpath.Count > 2 && xpath.EndsWith("cml", "molecule", "bondArray"))
                {
                    StoreBondData();
                    NewBondData();
                }
            }
            else if (element.Name == XName_CML_scalar)
            {
                //Residue number
                if (string.Equals("md:resNumber", DictRef, StringComparison.Ordinal))
                {
                    int myInt = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
                    currentResidue.SetNumber(myInt);
                }
                //ChargeGroup number
                else if (string.Equals("md:cgNumber", DictRef, StringComparison.Ordinal))
                {
                    int myInt = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
                    currentChargeGroup.SetNumber(myInt);
                }
            }
            else
            {
                base.EndElement(xpath, element);
            }
        }
コード例 #5
0
        // Parses residue's atom specified by the pdb-file line
        // returns residue number where atom has been added (for residue changing control)
        void ParseAtom(string pdbLine)
        {
            Atom atom = new Atom();
            atoms.Add(atom);

            Chain chain;
            char chainId = pdbLine[21];
            // FIXME: name of the chain must be gotten from DBREF record (?)
            if (!chains.TryGetValue(chainId, out chain)) chains[chainId] = chain = new Chain() { Name = chainId.ToString() };

            int number = int.Parse(pdbLine.Substring(22, 4), CultureInfo.InvariantCulture);

            Residue residue;
            if (chain.Residues.Count == 0 || (residue = chain.Residues[chain.Residues.Count - 1]).SequenceNumber != number)
            {
                residue = new Residue();
                chain.Residues.Add(residue);
                residue.SequenceNumber = number;
                residue.Name = pdbLine.Substring(17, 3);
            }
            residue.Atoms.Add(atom);

            atom.Position = GetAtomPosition(pdbLine);
            string atomName = pdbLine.Substring(12, 4).Trim();
            if (atomName == "CA" || atomName == "C1")
            {
                // Alfa-carbon has been got
                atom.Element = Element.GetBySymbol("C");
                residue.AlfaCarbon = atom;
            }
            else
            {
                atom.Element = GetAtomElement(pdbLine);
            }
        }
        private void openUpdateAllResiduesPanel(List <int> residueIDs)
        {
            if (residueIDs == null || residueIDs.Count == 0)
            {
                return;
            }

            List <Residue> residues = primaryStructure.GetResiduesByID(residueIDs);

            if (residues == null || residues.Count == 0)
            {
                return;
            }

            Residue selectedResidue = residues[0];

            bool             atomNamesAllTheSame      = true;
            HashSet <string> selectedResidueAtomNames = new HashSet <string>();

            foreach (Atom atom in selectedResidue.Atoms.Values)
            {
                selectedResidueAtomNames.Add(atom.Name);
            }

            foreach (Residue residue in residues)
            {
                HashSet <string> residueAtomNames = new HashSet <string>();
                foreach (Atom atom in residue.Atoms.Values)
                {
                    residueAtomNames.Add(atom.Name);
                }

                if (!residueAtomNames.SetEquals(selectedResidueAtomNames))
                {
                    atomNamesAllTheSame = false;
                }
            }

            List <string> atomNames = null;

            if (atomNamesAllTheSame)
            {
                atomNames = new List <string>();

                foreach (Atom atom in selectedResidue.Atoms.Values)
                {
                    atomNames.Add(atom.Name);
                }
            }

            bool residueSettingsAllTheSame = true;

            foreach (Residue residue in residues)
            {
                if (!moleculeRenderSettings.CustomResidueRenderSettings.ContainsKey(residue.ID) ||
                    !moleculeRenderSettings.CustomResidueRenderSettings[residue.ID].Equals(moleculeRenderSettings.CustomResidueRenderSettings[selectedResidue.ID]))
                {
                    residueSettingsAllTheSame = false;
                    break;
                }
            }
            ResidueRenderSettings panelResidueSettings = new ResidueRenderSettings();

            if (residueSettingsAllTheSame)
            {
                if (moleculeRenderSettings.CustomResidueRenderSettings.ContainsKey(selectedResidue.ID))
                {
                    panelResidueSettings = moleculeRenderSettings.CustomResidueRenderSettings[selectedResidue.ID].Clone();
                }
            }

            customSettingsPanel.Initialise(residueIDs, null, atomNames, ResidueUpdateType.All, panelResidueSettings, saveCustomResidueSettings, onCloseCustomResidueSettings);
        }
コード例 #7
0
ファイル: PDBParser.cs プロジェクト: hryknkgw/Molecule
 public Model Parse(System.IO.TextReader reader)
 {
     var model = new Model ();
     var missingResidues = new Queue<Residue> ();
     var reAtom = new System.Text.RegularExpressions.Regex ("^(?<recordName>ATOM  |HETATM)(?<serial>.{5}).(?<name>.{4})(?<altLoc>.{1})(?<resName>.{3}).(?<chainID>.{1})(?<resSeq>.{4})(?<iCode>.{1})...(?<x>.{8})(?<y>.{8})(?<z>.{8})(?<occupancy>.{6})(?<tempFactor>.{6})..........(?<element>.{2})(?<charge>.{2})$");
     var reRemark = new System.Text.RegularExpressions.Regex ("^REMARK.(?<remarkNum>.{3})");
     var reRemark2 = new System.Text.RegularExpressions.Regex ("^REMARK.  2.RESOLUTION..(?<resolution>.{7}).ANGSTROMS.");
     var reRemark465 = new System.Text.RegularExpressions.Regex ("^REMARK.465.(?<modelNo>.{3}).(?<resName>.{3}).(?<chainID>.{1})..(?<resSeq>.{4})(?<iCode>.{1})");
     while (reader.Peek() != -1) {
         var line = reader.ReadLine ();
         if (line.StartsWith ("ATOM  ") || line.StartsWith ("HETATM") ) {
             var m = reAtom.Match (line);
             var atom = (m.Groups ["recordName"].Value.Equals("ATOM  ")) ? new Atom (
                 int.Parse (m.Groups ["serial"].Value),
                 m.Groups ["name"].Value.Trim(),
                 m.Groups ["altLoc"].Value [0],
                 m.Groups ["resName"].Value.Trim(),
                 m.Groups ["chainID"].Value [0],
                 int.Parse (m.Groups ["resSeq"].Value),
                 m.Groups ["iCode"].Value [0],
                 double.Parse (m.Groups ["x"].Value),
                 double.Parse (m.Groups ["y"].Value),
                 double.Parse (m.Groups ["z"].Value),
                 double.Parse (m.Groups ["occupancy"].Value),
                 double.Parse (m.Groups ["tempFactor"].Value),
                 m.Groups ["element"].Value.Trim(),
                 m.Groups ["charge"].Value.Trim()
             ) : new HeteroAtom (
                 int.Parse (m.Groups ["serial"].Value),
                 m.Groups ["name"].Value.Trim(),
                 m.Groups ["altLoc"].Value [0],
                 m.Groups ["resName"].Value.Trim(),
                 m.Groups ["chainID"].Value [0],
                 int.Parse (m.Groups ["resSeq"].Value),
                 m.Groups ["iCode"].Value [0],
                 double.Parse (m.Groups ["x"].Value),
                 double.Parse (m.Groups ["y"].Value),
                 double.Parse (m.Groups ["z"].Value),
                 double.Parse (m.Groups ["occupancy"].Value),
                 double.Parse (m.Groups ["tempFactor"].Value),
                 m.Groups ["element"].Value.Trim(),
                 m.Groups ["charge"].Value.Trim()
             );
             if (model.Chains.Count == 0 || !(model.Chains.Last ().ChainID == atom.ChainID)) {
                 while (missingResidues.Count() > 0 && model.Chains.Count != 0 && missingResidues.First().ChainID == model.Chains.Last ().ChainID) {
                     model.Residues.Add (missingResidues.Dequeue ());
                 }
                 var chain = new Chain (atom.ChainID);
                 model.Chains.Add (chain);
             }
             atom.Chain = model.Chains.Last ();
             atom.Chain.Atoms.Add (atom);
             if (model.Residues.Count == 0 || !(model.Residues.Last ().ChainID == atom.ChainID && model.Residues.Last ().ResSeq == atom.ResSeq && model.Residues.Last ().ICode == atom.ICode)) {
                 var residue = new Residue (
                     atom.ResName,
                     atom.ChainID,
                     atom.ResSeq,
                     atom.ICode
                 );
                 while (missingResidues.Count() > 0 && missingResidues.First().ChainID == residue.ChainID && (missingResidues.First().ResSeq < residue.ResSeq || (missingResidues.First().ResSeq == residue.ResSeq && missingResidues.First().ICode < residue.ICode))) {
                     model.Residues.Add (missingResidues.Dequeue ());
                 }
                 model.Residues.Add (residue);
             }
             atom.Residue = model.Residues.Last ();
             atom.Residue.Atoms.Add (atom);
             model.Atoms.Add (atom);
         } else if (line.StartsWith ("REMARK")) {
             var m = reRemark.Match (line);
             if (m.Success) {
                 int remarkNum = int.Parse (m.Groups ["remarkNum"].Value);
                 switch (remarkNum) {
                 case 2:
                     m = reRemark2.Match (line);
                     if (m.Success) {
                         model.Resolution = double.Parse (m.Groups ["resolution"].Value);
                     }
                     break;
                 case 3:
                     double rfree;
                     if (double.TryParse (line.Replace ("REMARK   3   FREE R VALUE                     :", ""), out rfree)) {
                         model.RFree = rfree;
                     }
                     break;
                 case 465:
                     m = reRemark465.Match (line);
                     int resSeq;
                     if (m.Success && int.TryParse (m.Groups ["resSeq"].Value, out resSeq)) {
                         var missingResidue = new Residue (
                             m.Groups ["resName"].Value.Trim(),
                             m.Groups ["chainID"].Value [0],
                             resSeq,
                             m.Groups ["iCode"].Value [0]
                         );
                         missingResidues.Enqueue (missingResidue);
                     }
                     break;
                 default:
                     break;
                 }
             }
         }
     }
     while (missingResidues.Count() > 0 && model.Chains.Count != 0 && missingResidues.First().ChainID == model.Chains.Last ().ChainID) {
         model.Residues.Add (missingResidues.Dequeue ());
     }
     return model;
 }