public void UnregisterComponent(MoleculeComponent component)
 {
     if (components.Contains(component))
     {
         components.Remove(component);
     }
 }
 public virtual void SetStateOfComponent(MoleculeComponent component)
 {
     //UnityEngine.Profiling.Profiler.BeginSample("Set State");
     component.state        = state;
     component.lastBondName = bound ? bondName : string.Empty;
     //UnityEngine.Profiling.Profiler.EndSample();
 }
        public override bool React(MoleculeComponent[] components, ReactionCenter[] matchingReactionCenters)
        {
            if (components.Length > 0 && components[0] != null &&
                matchingReactionCenters.Length > 0 && matchingReactionCenters[0] != null)
            {
                components = new MoleculeComponent[] { components[0], components[0].boundComponent };
                matchingReactionCenters = new ReactionCenter[] { matchingReactionCenters[0], GetOtherReactionCenter(matchingReactionCenters[0]) };
                Dictionary <string, List <Molecule> > molecules;
                Complex newComplex;
                for (int i = 0; i < components.Length; i++)
                {
                    molecules  = components[i].complex.GetMoleculesAtEndOfBond(components[i]);
                    newComplex = reactor.MoveMoleculesToNewComplex(molecules);

                    components[i].SetToProductState(definition.reactionCenters[i]);
                    components[i].boundComponent = null;
                    newComplex.SetToProductState(matchingReactionCenters[i]);
                    newComplex.UpdateReactions();

                    SetProductColor(molecules);
                }

                return(true);
            }
            return(false);
        }
Example #4
0
        public Dictionary <string, List <Molecule> > GetMoleculesAtEndOfBond(MoleculeComponent component)
        {
            // TODO trace complex
            Dictionary <string, List <Molecule> > tracedMolecules = new Dictionary <string, List <Molecule> >();

            tracedMolecules.Add(component.molecule.definition.moleculeName, new List <Molecule>(new Molecule[] { component.molecule }));
            return(tracedMolecules);
        }
 public bool RegisterComponent(MoleculeComponent component)
 {
     if (!components.Contains(component))
     {
         if (ComponentIsInReactionCenter(component))
         {
             components.Add(component);
             return(true);
         }
     }
     return(false);
 }
 public ReactionCenter GetReactionCenterForComponent(MoleculeComponent component)
 {
     foreach (ReactionCenter reactionCenter in definition.reactionCenters)
     {
         if (//reactionCenter.reactantComplex.Matches( component.complex.molecules ) &&
             reactionCenter.reactantMolecule.Matches(component.molecule) &&
             reactionCenter.reactantComponent.Matches(component))
         {
             return(reactionCenter);
         }
     }
     return(null);
 }
Example #7
0
        protected void RelativelyPosition(MoleculeComponent parentComponent, MoleculeComponent childComponent)
        {
            // move the complex with the fewest molecules
            int childMoleculeCount  = childComponent.complex.GetNumberOfMolecules();
            int parentMoleculeCount = parentComponent.complex.GetNumberOfMolecules();

            if (parentMoleculeCount < childMoleculeCount)
            {
                MoleculeComponent tempComponent = childComponent;
                childComponent  = parentComponent;
                parentComponent = tempComponent;

                int tempCount = childMoleculeCount;
                childMoleculeCount  = parentMoleculeCount;
                parentMoleculeCount = tempCount;
            }

            childComponent.molecule.SetWorldTransform(reactor.GetWorldTransformForBindingMolecule(childComponent.molecule.position, childComponent.molecule.rotation, childComponent.position,
                                                                                                  childComponent.rotation, parentComponent.position, parentComponent.rotation));
        }
Example #8
0
 public virtual bool ReactWith(MoleculeComponent other)
 {
     if (IsNear(other))
     {
         bindReactionCenters.Shuffle();
         other.bindReactionCenters.Shuffle();
         foreach (ReactionCenter reactionCenter in bindReactionCenters)
         {
             foreach (ReactionCenter otherReactionCenter in other.bindReactionCenters)
             {
                 if (reactionCenter != otherReactionCenter && reactionCenter.reaction == otherReactionCenter.reaction && reactionCenter.reaction.ShouldHappen())
                 {
                     if (reactionCenter.reaction.React(new MoleculeComponent[] { this, other }, new ReactionCenter[] { reactionCenter, otherReactionCenter }))
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
 public ComponentPattern(MoleculeComponent moleculeComponent)
 {
     _componentName = moleculeComponent.componentName;
     state          = moleculeComponent.state;
     _bound         = moleculeComponent.bound;
 }
 protected bool ComponentIsInReactionCenter(MoleculeComponent component)
 {
     return(definition.reactionCenters[0].reactantMolecule.Matches(component.molecule) &&
            definition.reactionCenters[0].reactantComponent.Matches(component));
 }
Example #11
0
 bool IsNear(MoleculeComponent other)
 {
     return(other != this &&
            Vector3.Distance(position, other.position) < interactionRadius + other.interactionRadius);
 }