Пример #1
0
        //start naive
        private List <Fragment> generateFragByNaive()
        {
            int percent = 0;

            progressBar1.Maximum = _chemStructures[0].countBonds();
            int PBar_Percent = 0;

            progressBar1.Value = PBar_Percent;
            progressBar1.Step  = 1;


            //Do this to preserve hydrogen numbers so that breaking bonds doesn't cause re-ordering.
            foreach (IndigoObject atom in _chemStructures[0].iterateAtoms())
            {
                atom.countHydrogens();
            }

            List <Fragment> _frags = new List <Fragment>();


            foreach (IndigoObject bond in _chemStructures[0].iterateBonds())
            {
                progressBar1.PerformStep();
                IndigoObject tempStructure = _chemStructures[0].clone();
                percent     = (int)(progressBar1.Value / (progressBar1.Maximum * 100));
                label3.Text = percent.ToString() + "%";

                fragmentationRule naiveFragment = new fragmentationRule();
                naiveFragment._atomId1 = bond.source().index();
                naiveFragment._atomId2 = bond.destination().index();
                naiveFragment._bondId  = bond.index();

                tempStructure.getBond(bond.index()).remove();

                if (tempStructure.countComponents() > 1)
                {
                    for (int i = 0; i < tempStructure.countComponents(); i++)
                    {
                        IndigoObject currFragment   = tempStructure.component(i).clone();
                        double       totalMassShift = 0.00;
                        //Get R Group Masses
                        foreach (IndigoObject rgroup in _chemStructures[0].iterateAtoms())
                        {
                            if (rgroup.symbol().Equals("R"))
                            {
                                if (rgroup.componentIndex() == i)
                                {
                                    try
                                    {
                                        double RgrpMassShift = double.Parse(rmasses[rmasses.IndexOf(rmasses.Find(x => x.index == rgroup.index()))].interfaceText.Text);
                                        Console.Out.WriteLine("BEFORE " + totalMassShift);
                                        totalMassShift += RgrpMassShift;
                                        Console.Out.WriteLine("AFTER " + totalMassShift);
                                    }
                                    catch (FormatException e)
                                    {
                                        MessageBox.Show("All R-Groups must have masses... R Group #" + rgroup.index() + " does not!");
                                    }
                                    //Console.Out.WriteLine(rgroup.index() + " has a mass of " +RgrpMassShift);
                                }
                            }
                        }

                        Fragment currFragAdd = new Fragment(naiveFragment);
                        currFragAdd.mass = (currFragment.monoisotopicMass() + totalMassShift);
                        _frags.Add(currFragAdd);
                    }
                }
            }
            return(_frags);
        }
Пример #2
0
        private List <Fragment> recursiveFragGeneration(IndigoObject prefrag, List <fragmentationRule> _copyRules, string currName = "")
        {
            List <fragmentationRule> copyRules = new List <fragmentationRule>();

            copyRules.AddRange(_copyRules);
            List <Fragment> _frags = new List <Fragment>();

            foreach (IndigoObject structure in prefrag.iterateComponents())
            {
                foreach (fragmentationRule rule in _copyRules)
                {
                    IndigoObject temp = structure.clone();
                    try
                    {
                        temp.getBond(rule._bondId).remove();
                        if (rule._bondId2 != -1)
                        {
                            temp.getBond(rule._bondId2).remove();
                        }
                        currName = currName + "+" + rule.fragmentName;
                        if (_copyRules.Count == _rules.Count)
                        {
                            currName = rule.fragmentName;
                        }

                        Console.Out.WriteLine("RULE NAME " + currName);

                        for (int i = 0; i < temp.countComponents(); i++)
                        {
                            IndigoObject currFragment   = temp.component(i).clone();
                            double       totalMassShift = 0.00;
                            totalMassShift = calculateRgrpMassShift(rule, currFragment);
                            Fragment currFragAdd = new Fragment(rule);

                            Console.Out.WriteLine("MASS BEFORE " + totalMassShift);
                            foreach (IndigoObject atoms in temp.component(i).iterateAtoms())
                            {
                                if (atoms.componentIndex() == i)
                                {
                                    if (atoms.index() == rule._atomId1)
                                    {
                                        totalMassShift = totalMassShift + rule._MassShift1;
                                    }
                                    if (atoms.index() == rule._atomId2)
                                    {
                                        totalMassShift = totalMassShift + rule._MassShift2;
                                    }
                                }
                            }
                            currFragAdd.mass         = (currFragment.monoisotopicMass() + totalMassShift);
                            currFragAdd.fragmentName = currName;
                            _frags.Add(currFragAdd);
                            copyRules.Remove(rule);
                        }
                        _frags.AddRange(recursiveFragGeneration(temp, copyRules, currName));
                    }

                    catch (Exception e)
                    {
                        Console.Out.WriteLine("That Atom doesn't exist in thsi structure!" + e);
                    }
                }
            }

            // renderMolecule2(prefrag, prefrag.monoisotopicMass().ToString());
            return(_frags);
        }