public Bond(MoleculePattern _moleculePattern1, ComponentPattern _componentPattern1, MoleculePattern _moleculePattern2, ComponentPattern _componentPattern2) { moleculePattern1 = _moleculePattern1; componentPattern1 = _componentPattern1; moleculePattern2 = _moleculePattern2; componentPattern2 = _componentPattern2; }
public Molecule(MoleculePattern moleculePattern, RelativeTransform _localTransform, Complex _complex) { localTransform = new RelativeTransform(_localTransform); complex = _complex; definition = moleculePattern.moleculeDef; collisionRadius = interactionRadius = definition.radius; interactionRadius += 1f; CreateComponents(moleculePattern); SetColorForCurrentState(); }
bool MoleculePatternWasUsed(MoleculePattern moleculePattern, List <Molecule> molecules) { foreach (Molecule molecule in molecules) { if (molecule.stateWasUpdated && moleculePattern.Matches(molecule)) { return(true); } } return(false); }
protected void CreateComponents(MoleculePattern moleculePattern) { foreach (List <ComponentDef> aTypeOfComponent in definition.componentDefs.Values) { foreach (ComponentDef componentDef in aTypeOfComponent) { CreateComponent(componentDef); } } moleculePattern.SetStateOfMolecule(this); }
void SetProductStatesOfAttachedMolecules(Molecule molecule, MoleculePattern productMoleculeRef) { Dictionary <string, Bond> bonds = GetBonds(productMoleculeRef); foreach (string componentName in molecule.components.Keys) { foreach (MoleculeComponent component in molecule.components[componentName]) { if (component.boundComponent != null && !component.boundComponent.molecule.stateWasUpdated && bonds.ContainsKey(component.lastBondName)) { component.boundComponent.SetToProductState(bonds[component.lastBondName].moleculePattern2, bonds[component.lastBondName].componentPattern2); } } } }
public override bool Equals(object obj) { //UnityEngine.Profiling.Profiler.BeginSample("Comparisons"); MoleculePattern other = obj as MoleculePattern; if (other != null) { return(Matches(other)); } Molecule molecule = obj as Molecule; if (molecule != null) { return(Matches(molecule)); } //UnityEngine.Profiling.Profiler.EndSample(); return(false); }
Dictionary <string, Bond> GetBonds(MoleculePattern moleculePattern) { Bond bond; Dictionary <string, Bond> bonds = new Dictionary <string, Bond>(); foreach (string componentName in moleculePattern.componentPatterns.Keys) { foreach (ComponentPattern componentPattern in moleculePattern.componentPatterns[componentName]) { if (!componentPattern.bound || componentPattern.bondName.Contains("+") || bonds.ContainsKey(componentPattern.bondName)) { continue; } bond = GetBondForComponent(moleculePattern, componentPattern); if (bond != null) { bonds.Add(componentPattern.bondName, bond); } } } return(bonds); }
public virtual void SetStateOfComplex(Molecule molecule1, MoleculePattern productMolecule1, Molecule molecule2, MoleculePattern productMolecule2) { //get references to the reaction center molecules in this complex pattern MoleculePattern productMoleculeRef1 = null, productMoleculeRef2 = null; foreach (string moleculeName in moleculePatterns.Keys) { foreach (MoleculePattern moleculePattern in moleculePatterns[moleculeName]) { if (productMolecule1.Matches(moleculePattern)) { productMoleculeRef1 = moleculePattern; } else if (productMolecule2.Matches(moleculePattern)) { productMoleculeRef2 = moleculePattern; } } } //set states of attached molecules SetProductStatesOfAttachedMolecules(molecule1, productMoleculeRef1); SetProductStatesOfAttachedMolecules(molecule2, productMoleculeRef2); }
Bond GetBondForComponent(MoleculePattern moleculePattern, ComponentPattern componentPattern) { foreach (string moleculeName in moleculePatterns.Keys) { foreach (MoleculePattern otherMoleculePattern in moleculePatterns[moleculeName]) { if (otherMoleculePattern == moleculePattern) { continue; } foreach (string otherComponentName in otherMoleculePattern.componentPatterns.Keys) { foreach (ComponentPattern otherComponentPattern in otherMoleculePattern.componentPatterns[otherComponentName]) { if (otherComponentPattern.bound && otherComponentPattern.bondName == componentPattern.bondName) { return(new Bond(moleculePattern, componentPattern, otherMoleculePattern, otherComponentPattern)); } } } } } return(null); }
public bool Matches(MoleculePattern other) { if (!other.moleculeDef.Equals(moleculeDef)) { //Debug.Log( "molecules don't match" ); return(false); } Dictionary <ComponentPattern, int> thisComponentsInState = new Dictionary <ComponentPattern, int>(); Dictionary <ComponentPattern, int> otherComponentsInState = new Dictionary <ComponentPattern, int>(); foreach (string componentName in componentPatterns.Keys) { if (!other.componentPatterns.ContainsKey(componentName)) //does this type of component exist in the other? { //Debug.Log( "component " + componentName + " doesn't exist in other" ); return(false); } foreach (ComponentPattern thisComponentPattern in componentPatterns[componentName]) //how many of our components are in each state? { if (!thisComponentsInState.ContainsKey(thisComponentPattern)) { thisComponentsInState[thisComponentPattern] = 1; } else { thisComponentsInState[thisComponentPattern]++; } } foreach (ComponentPattern otherComponentPattern in other.componentPatterns[componentName]) //how many of the other's components are in each state? { if (!otherComponentsInState.ContainsKey(otherComponentPattern)) { otherComponentsInState[otherComponentPattern] = 1; } else { otherComponentsInState[otherComponentPattern]++; } } foreach (ComponentPattern thisComponentPattern in thisComponentsInState.Keys) //does the other at least have as many components in each state as we do? { if (!otherComponentsInState.ContainsKey(thisComponentPattern)) { //Debug.Log( "there are no " + componentName + " components that match pattern " + thisComponentPattern ); return(false); } if (otherComponentsInState[thisComponentPattern] < thisComponentsInState[thisComponentPattern]) { //Debug.Log( "number of " + componentName + " components that match pattern " + thisComponentPattern + " is " //+ otherComponentsInState[thisComponentPattern] + " when it should be at least " + thisComponentsInState[thisComponentPattern] ); return(false); } } thisComponentsInState.Clear(); otherComponentsInState.Clear(); } return(true); }
public bool Matches(Dictionary <string, List <Molecule> > molecules) { //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 (!molecules.ContainsKey(moleculeName)) //does this type of molecule exist in the other? { //Debug.Log( "molecule " + moleculeName + " doesn't exist in molecules" ); 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 (Molecule otherMolecule in molecules[moleculeName]) //how many of the other's molecules are in each state? { MoleculePattern otherMoleculePattern = new MoleculePattern(otherMolecule); 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); }
public void SetToProductState(MoleculePattern productMoleculePattern) { productMoleculePattern.SetStateOfMolecule(this); stateWasUpdated = true; }
public void SetToProductState(ComplexPattern productComplex, Molecule molecule1, MoleculePattern productMolecule1, Molecule molecule2, MoleculePattern productMolecule2) { productComplex.SetStateOfComplex(molecule1, productMolecule1, molecule2, productMolecule2); ConnectBoundComponents(); }
public void SetToProductState(MoleculePattern productMolecule, ComponentPattern productComponent) { productComponent.SetStateOfComponent(this); stateWasUpdated = true; molecule.SetToProductState(productMolecule); }