コード例 #1
0
ファイル: Residue.cs プロジェクト: roddickchen/NCDK
 public void SetParentMolecule(MDMolecule parentMolecule)
 {
     this.parentMolecule = parentMolecule;
 }
コード例 #2
0
ファイル: Residue.cs プロジェクト: roddickchen/NCDK
 /// <summary>
 /// Constructor to create a Residue based on an AC, a number, and a MDMolecule.
 /// </summary>
 public Residue(IAtomContainer container, int number, MDMolecule parentMolecule)
     : base(container)
 {
     this.number         = number;
     this.parentMolecule = parentMolecule;
 }
コード例 #3
0
ファイル: ChargeGroup.cs プロジェクト: roddickchen/NCDK
 /// <summary>
 /// Constructor to create a ChargeGroup based on an AC, a number, and a MDMolecule.
 /// </summary>
 /// <param name="container"></param>
 /// <param name="number"></param>
 /// <param name="parentMolecule"></param>
 public ChargeGroup(IAtomContainer container, int number, MDMolecule parentMolecule)
     : base(container)
 {
     this.number         = number;
     this.parentMolecule = parentMolecule;
 }
コード例 #4
0
        /// <summary>
        /// Customize Molecule.
        /// </summary>
        /// <param name="molecule"></param>
        /// <param name="nodeToAdd"></param>
        public void Customize(IAtomContainer molecule, object nodeToAdd)
        {
            if (!(nodeToAdd is CMLMolecule))
            {
                throw new CDKException("NodeToAdd must be of type nu.xom.Element!");
            }

            //The nodeToAdd
            CMLMolecule molToCustomize = (CMLMolecule)nodeToAdd;

            if ((molecule is MDMolecule))
            {
                MDMolecule mdmol = (MDMolecule)molecule;
                molToCustomize.Convention = "md:mdMolecule";
                molToCustomize.SetAttributeValue(XNamespace.Xmlns + "md", NS_MD.NamespaceName);

                //Residues
                if (mdmol.GetResidues().Count > 0)
                {
                    foreach (var residue in mdmol.GetResidues())
                    {
                        int number = residue.GetNumber();

                        CMLMolecule resMol = new CMLMolecule
                        {
                            DictRef = "md:residue",
                            Title   = residue.Name
                        };

                        //Append resNo
                        CMLScalar residueNumber = new CMLScalar(number);
                        residueNumber.SetAttributeValue(Attribute_dictRef, "md:resNumber");
                        resMol.Add(residueNumber);

                        // prefix for residue atom id
                        string rprefix = "r" + number;
                        //Append atoms
                        CMLAtomArray ar = new CMLAtomArray();
                        for (int i = 0; i < residue.Atoms.Count; i++)
                        {
                            CMLAtom cmlAtom = new CMLAtom
                            {
                                //                        Console.Out.WriteLine("atom ID: "+ residue.Atoms[i].Id);
                                //                        cmlAtom.AddAttribute(new Attribute("ref", residue.Atoms[i].Id));
                                // the next thing is better, but  exception
                                //
                                // setRef to keep consistent usage
                                // setId to satisfy Jumbo 54. need for all atoms to have id
                                Ref = residue.Atoms[i].Id,
                                Id  = rprefix + "_" + residue.Atoms[i].Id
                            };
                            ar.Add(cmlAtom);
                        }
                        resMol.Add(ar);

                        molToCustomize.Add(resMol);
                    }
                }

                //Chargegroups
                if (mdmol.GetChargeGroups().Count > 0)
                {
                    foreach (var chargeGroup in mdmol.GetChargeGroups())
                    {
                        int number = chargeGroup.GetNumber();

                        //FIXME: persist the ChargeGroup
                        CMLMolecule cgMol = new CMLMolecule
                        {
                            DictRef = "md:chargeGroup"
                        };
                        // etc: add name, refs to atoms etc

                        //Append chgrpNo
                        CMLScalar cgNo = new CMLScalar(number)
                        {
                            DictRef = "md:cgNumber"
                        };
                        cgMol.Add(cgNo);

                        // prefix for residue atom id
                        string cprefix = "cg" + number;

                        //Append atoms from chargeGroup as it is an AC
                        CMLAtomArray ar = new CMLAtomArray();
                        for (int i = 0; i < chargeGroup.Atoms.Count; i++)
                        {
                            CMLAtom cmlAtom = new CMLAtom
                            {
                                // setRef to keep consistent usage
                                // setId to satisfy Jumbo 5.4 need for all atoms to have id
                                Ref = chargeGroup.Atoms[i].Id,
                                Id  = cprefix + "_" + chargeGroup.Atoms[i].Id
                            };

                            //Append switching atom?
                            if (chargeGroup.Atoms[i].Equals(chargeGroup.GetSwitchingAtom()))
                            {
                                CMLScalar scalar = new CMLScalar
                                {
                                    DictRef = "md:switchingAtom"
                                };
                                cmlAtom.Add(scalar);
                            }
                            ar.Add(cmlAtom);
                        }
                        cgMol.Add(ar);

                        molToCustomize.Add(cgMol);
                    }
                }
            }
        }
コード例 #5
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);
            }
        }