public MoleculeInitData(ComplexPattern _complexPattern, Dictionary <string, List <RelativeTransform> > _moleculeTransforms,
                         BindReaction[] _relevantBindReactions,
                         CollisionFreeReaction[] _relevantCollisionFreeReactions)
 {
     complexPattern                 = _complexPattern;
     moleculeTransforms             = _moleculeTransforms;
     relevantBindReactions          = _relevantBindReactions;
     relevantCollisionFreeReactions = _relevantCollisionFreeReactions;
 }
 public bool ComplexIsReactant(ComplexPattern complexPattern)
 {
     foreach (ReactionCenter reactionCenter in definition.reactionCenters)
     {
         if (reactionCenter.reactantComplex.Matches(complexPattern))
         {
             return(true);
         }
     }
     return(false);
 }
        protected CollisionFreeReaction[] GetRelevantCollisionFreeReactions(ComplexPattern complexPattern)
        {
            List <CollisionFreeReaction> reactionsList = new List <CollisionFreeReaction>();

            foreach (CollisionFreeReaction reaction in collisionFreeReactions)
            {
                if (reaction.ComplexIsReactant(complexPattern))
                {
                    reactionsList.Add(reaction);
                }
            }
            return(reactionsList.ToArray());
        }
        protected BindReaction[] GetRelevantBindReactions(ComplexPattern complexPattern)
        {
            List <BindReaction> reactionsList = new List <BindReaction>();

            foreach (BindReaction reaction in bindReactions)
            {
                if (reaction.ComplexIsReactant(complexPattern))
                {
                    reactionsList.Add(reaction);
                }
            }
            return(reactionsList.ToArray());
        }
示例#5
0
 public ComplexConcentration(ComplexPattern _complexPattern, float _concentration)
 {
     complexPattern = _complexPattern;
     complexPattern.Init();
     concentration = _concentration;
 }
        protected virtual Dictionary <string, List <RelativeTransform> > CalculateMoleculeTransforms(ComplexPattern complexPattern)
        {
            Dictionary <string, List <RelativeTransform> > transforms = new Dictionary <string, List <RelativeTransform> >();
            Vector3 averagePosition = Vector3.zero;

            //temp transforms for calculation
            Transform molecule1  = new GameObject("molecule1").transform;
            Transform molecule2  = new GameObject("molecule2").transform;
            Transform component1 = new GameObject("component1").transform;
            Transform component2 = new GameObject("component2").transform;

            component1.SetParent(molecule1);
            component2.SetParent(molecule2);

            List <ComponentPattern> foundComponents = new List <ComponentPattern>();
            ComponentPattern        componentPattern1, componentPattern2;
            ComponentDef            componentDef;
            int n = 0;

            foreach (string moleculeName1 in complexPattern.moleculePatterns.Keys)
            {
                if (!transforms.ContainsKey(moleculeName1))
                {
                    transforms.Add(moleculeName1, new List <RelativeTransform>());
                }
                if (transforms.Keys.Count == 1)
                {
                    transforms[moleculeName1].Add(new RelativeTransform(Vector3.zero, Vector3.zero));
                    n++;
                }
                for (int m1 = 0; m1 < complexPattern.moleculePatterns[moleculeName1].Count; m1++)
                {
                    foreach (string componentName1 in complexPattern.moleculePatterns[moleculeName1][m1].componentPatterns.Keys)
                    {
                        for (int c1 = 0; c1 < complexPattern.moleculePatterns[moleculeName1][m1].componentPatterns[componentName1].Count; c1++)
                        {
                            componentPattern1 = complexPattern.moleculePatterns[moleculeName1][m1].componentPatterns[componentName1][c1];
                            if (foundComponents.Contains(componentPattern1))
                            {
                                continue;
                            }
                            if (complexPattern.moleculePatterns[moleculeName1][m1].componentPatterns[componentName1][c1].bound)
                            {
                                foreach (string moleculeName2 in complexPattern.moleculePatterns.Keys)
                                {
                                    for (int m2 = 0; m2 < complexPattern.moleculePatterns[moleculeName2].Count; m2++)
                                    {
                                        if (moleculeName2 == moleculeName1 && m2 == m1)
                                        {
                                            continue;
                                        }
                                        foreach (string componentName2 in complexPattern.moleculePatterns[moleculeName2][m2].componentPatterns.Keys)
                                        {
                                            for (int c2 = 0; c2 < complexPattern.moleculePatterns[moleculeName2][m2].componentPatterns[componentName2].Count; c2++)
                                            {
                                                componentPattern2 = complexPattern.moleculePatterns[moleculeName2][m2].componentPatterns[componentName2][c2];
                                                if (componentPattern2.bound && !foundComponents.Contains(componentPattern2) && componentPattern1.bondName == componentPattern2.bondName)
                                                {
                                                    foundComponents.Add(componentPattern1);
                                                    foundComponents.Add(componentPattern2);

                                                    molecule1.position = transforms[moleculeName1][m1].position;
                                                    molecule1.rotation = Quaternion.Euler(transforms[moleculeName1][m1].rotation);
                                                    componentDef       = complexPattern.moleculePatterns[moleculeName1][m1].moleculeDef.componentDefs[componentName1][c1];
                                                    componentDef.transformOnMolecule.Apply(molecule1, component1);

                                                    molecule2.position = Vector3.zero;
                                                    molecule2.rotation = Quaternion.identity;
                                                    componentDef       = complexPattern.moleculePatterns[moleculeName2][m2].moleculeDef.componentDefs[componentName2][c2];
                                                    componentDef.transformOnMolecule.Apply(molecule2, component2);

                                                    molecule2.position = component1.TransformPoint(component2.InverseTransformPoint(molecule2.position));
                                                    molecule2.rotation = molecule2.rotation * Quaternion.Inverse(component2.rotation) * component1.rotation;

                                                    if (!transforms.ContainsKey(moleculeName2))
                                                    {
                                                        transforms.Add(moleculeName2, new List <RelativeTransform>());
                                                        n++;
                                                    }
                                                    transforms[moleculeName2].Add(new RelativeTransform(molecule2.position, molecule2.rotation.eulerAngles));
                                                    averagePosition += transforms[moleculeName2][m2].position;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            averagePosition /= n;
            foreach (string moleculeName in transforms.Keys)
            {
                foreach (RelativeTransform t in transforms[moleculeName])
                {
                    t.position -= averagePosition;
                }
            }

            Destroy(molecule1.gameObject);
            Destroy(molecule2.gameObject);

            return(transforms);
        }
        public bool Matches(ComplexPattern other)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("Comparisons");
            Dictionary <MoleculePattern, int> thisComponentsInState  = new Dictionary <MoleculePattern, int>();
            Dictionary <MoleculePattern, int> otherComponentsInState = new Dictionary <MoleculePattern, int>();

            foreach (string moleculeName in moleculePatterns.Keys)
            {
                if (!other.moleculePatterns.ContainsKey(moleculeName))   //does this type of molecule exist in the other?
                {
                    //Debug.Log( "molecule " + moleculeName + " doesn't exist in other" );
                    return(false);
                }

                foreach (MoleculePattern thisMoleculePattern in moleculePatterns[moleculeName]) //how many of our molecules are in each state?
                {
                    if (!thisComponentsInState.ContainsKey(thisMoleculePattern))
                    {
                        thisComponentsInState[thisMoleculePattern] = 1;
                    }
                    else
                    {
                        thisComponentsInState[thisMoleculePattern]++;
                    }
                }
                foreach (MoleculePattern otherMoleculePattern in other.moleculePatterns[moleculeName]) //how many of the other's molecules are in each state?
                {
                    if (!otherComponentsInState.ContainsKey(otherMoleculePattern))
                    {
                        otherComponentsInState[otherMoleculePattern] = 1;
                    }
                    else
                    {
                        otherComponentsInState[otherMoleculePattern]++;
                    }
                }

                foreach (MoleculePattern thisMoleculePattern in thisComponentsInState.Keys) //does the other at least have as many molecules in each state as we do?
                {
                    MoleculePattern matchingMoleculePattern = null;
                    foreach (MoleculePattern otherMoleculePattern in otherComponentsInState.Keys)
                    {
                        if (thisMoleculePattern.Matches(otherMoleculePattern))
                        {
                            matchingMoleculePattern = otherMoleculePattern;
                            break;
                        }
                    }
                    if (matchingMoleculePattern == null)
                    {
                        //Debug.Log( "there are no " + moleculeName + " molecules that match pattern " + thisMoleculePattern );
                        return(false);
                    }
                    if (otherComponentsInState[matchingMoleculePattern] < thisComponentsInState[thisMoleculePattern])
                    {
                        //Debug.Log( "number of " + moleculeName + " molecules that match pattern " + thisMoleculePattern + " is "
                        //+ otherComponentsInState[matchingMoleculePattern] + " when it should be at least " + thisComponentsInState[thisMoleculePattern] );
                        return(false);
                    }
                }

                thisComponentsInState.Clear();
                otherComponentsInState.Clear();
            }
            //UnityEngine.Profiling.Profiler.EndSample();
            return(true);
        }
示例#8
0
 public void SetToProductState(ComplexPattern productComplex, Molecule molecule1, MoleculePattern productMolecule1, Molecule molecule2, MoleculePattern productMolecule2)
 {
     productComplex.SetStateOfComplex(molecule1, productMolecule1, molecule2, productMolecule2);
     ConnectBoundComponents();
 }