Exemplo n.º 1
0
        public override void EndElement(CMLStack xpath, XElement element)
        {
            var local = element.Name.LocalName;

            switch (local)
            {
            case "reaction":
                CurrentReactionSet.Add(CurrentReaction);
                CurrentChemModel.ReactionSet = CurrentReactionSet;
                break;

            case "reactionList":
                CurrentChemModel.ReactionSet = CurrentReactionSet;
                /* FIXME: this should be when document is closed! */
                break;

            case "reactant":
                CurrentReaction.Reactants.Add(CurrentMolecule);
                break;

            case "product":
                CurrentReaction.Products.Add(CurrentMolecule);
                break;

            case "substance":
                CurrentReaction.Agents.Add(CurrentMolecule);
                break;

            case "molecule":
                Debug.WriteLine("Storing Molecule");
                //if the current molecule exists in the currentMoleculeSet means that is a reference in these.
                if (CurrentMoleculeSet.GetMultiplier(CurrentMolecule) == -1)
                {
                    base.StoreData();
                }
                // do nothing else but store atom/bond information
                break;

            default:
                base.EndElement(xpath, element);
                break;
            }
        }
Exemplo n.º 2
0
        public override void EndElement(CMLStack xpath, XElement element)
        {
            string name = element.Name.LocalName;

            // OLD +++++++++++++++++++++++++++++++++++++++++++++
            switch (name)
            {
            case "list":
                if (connectionTable && !isBond)
                {
                    Debug.WriteLine("End Connection Table");
                    connectionTable = false;
                    // OLD +++++++++++++++++++++++++++++++++++++++++++++
                }
                break;

            case "molecule":
                StoreData();
                if (xpath.Count == 1)
                {
                    //                cdo.EndObject("Molecule");
                    if (CurrentMolecule is IAtomContainer)
                    {
                        Debug.WriteLine("Adding molecule to set");
                        CurrentMoleculeSet.Add(CurrentMolecule);
                        Debug.WriteLine($"#mols in set: {CurrentMoleculeSet.Count}");
                    }
                    else if (CurrentMolecule is ICrystal)
                    {
                        Debug.WriteLine("Adding crystal to chemModel");
                        CurrentChemModel.Crystal = (ICrystal)CurrentMolecule;
                        CurrentChemSequence.Add(CurrentChemModel);
                    }
                }
                break;
            }
            isELSYM = false;
            isBond  = false;
        }
Exemplo n.º 3
0
        public override void StartElement(CMLStack xpath, XElement element)
        {
            if (string.Equals("reaction", element.Name.LocalName, StringComparison.Ordinal))
            {
                //            cdo.StartObject("Reaction");
                if (CurrentReactionSet == null)
                {
                    CurrentReactionSet = CurrentChemFile.Builder.NewReactionSet();
                }
                CurrentReaction = CurrentChemFile.Builder.NewReaction();
                string id = AttGetValue(element.Attributes(), "id");
                if (id != null)
                {
                    CurrentReaction.Id = id;
                }
                //                cdo.SetObjectProperty("Reaction", "id", id);
            }
            else if (string.Equals("reactionList", element.Name.LocalName, StringComparison.Ordinal))
            {
                //            cdo.StartObject("ReactionSet");
                CurrentReactionSet = CurrentChemFile.Builder.NewReactionSet();
                string id = AttGetValue(element.Attributes(), "id");
                if (id != null)
                {
                    CurrentReactionSet.Id = id;
                }
                //                cdo.SetObjectProperty("reactionList", "id", id);
            }
            else if (string.Equals("reactant", element.Name.LocalName, StringComparison.Ordinal))
            {
                //            cdo.StartObject("Reactant");
                if (CurrentReaction == null)
                {
                    if (CurrentReactionSet == null)
                    {
                        CurrentReactionSet = CurrentChemFile.Builder.NewReactionSet();
                    }
                    CurrentReaction = CurrentChemFile.Builder.NewReaction();
                }
                CurrentMolecule = CurrentChemFile.Builder.NewAtomContainer();
#if DEBUG
                objectType = "Reactant";
#endif
                string id = AttGetValue(element.Attributes(), "id");
                if (id != null)
                {
                    CurrentMolecule.Id = id;
                }
                else
                {
                    string ref_ = AttGetValue(element.Attributes(), "ref");
                    if (ref_ != null)
                    {
                        CurrentMolecule.Id = ref_;
                    }
                }
                //                cdo.SetObjectProperty("Reactant", "id", id);
            }
            else if (string.Equals("product", element.Name.LocalName, StringComparison.Ordinal))
            {
                //            cdo.StartObject("Product");
                if (CurrentReaction == null)
                {
                    if (CurrentReactionSet == null)
                    {
                        CurrentReactionSet = CurrentChemFile.Builder.NewReactionSet();
                    }
                    CurrentReaction = CurrentChemFile.Builder.NewReaction();
                }
                CurrentMolecule = CurrentChemFile.Builder.NewAtomContainer();
#if DEBUG
                objectType = "Product";
#endif
                string id = AttGetValue(element.Attributes(), "id");
                if (id != null)
                {
                    CurrentMolecule.Id = id;
                }
                else
                {
                    string ref_ = AttGetValue(element.Attributes(), "ref");
                    if (ref_ != null)
                    {
                        CurrentMolecule.Id = ref_;
                    }
                }
                //                cdo.SetObjectProperty("Product", "id", id);
            }
            else if (string.Equals("substance", element.Name.LocalName, StringComparison.Ordinal))
            {
                //            cdo.StartObject("Agent");
                if (CurrentReaction == null)
                {
                    if (CurrentReactionSet == null)
                    {
                        CurrentReactionSet = CurrentChemFile.Builder.NewReactionSet();
                    }
                    CurrentReaction = CurrentChemFile.Builder.NewReaction();
                }
                CurrentMolecule = CurrentChemFile.Builder.NewAtomContainer();
#if DEBUG
                objectType = "Agent";
#endif
                string id = AttGetValue(element.Attributes(), "id");
                if (id != null)
                {
                    CurrentMolecule.Id = id;
                }
                else
                {
                    string ref_ = AttGetValue(element.Attributes(), "ref");
                    if (ref_ != null)
                    {
                        CurrentMolecule.Id = ref_;
                    }
                }
                //                cdo.SetObjectProperty("Agent", "id", id);
            }
            else if (string.Equals("molecule", element.Name.LocalName, StringComparison.Ordinal))
            {
                // clear existing molecule data
                base.NewMolecule();
                string id = AttGetValue(element.Attributes(), "id");
                if (id != null)
                {
                    // check for existing molecule of that id
                    IAtomContainer existing = GetMoleculeFromID(CurrentMoleculeSet, id);
                    if (existing != null)
                    {
                        CurrentMolecule = existing;
                    }
                    else
                    {
                        CurrentMolecule.Id = id;
                    }
                }
                else
                {
                    string ref_ = AttGetValue(element.Attributes(), "ref");
                    if (ref_ != null)
                    {
                        IAtomContainer atomC = GetMoleculeFromID(CurrentMoleculeSet, ref_);

                        // if there was no molecule create a new one for the reference. this
                        // happens when the reaction is defined before the molecule set
                        if (atomC == null)
                        {
                            atomC    = CurrentChemFile.Builder.NewAtomContainer();
                            atomC.Id = ref_;
                            CurrentMoleculeSet.Add(atomC);
                        }

                        base.CurrentMolecule = atomC;
                    }
                }
            }
            else
            {
                base.StartElement(xpath, element);
            }
        }