public Bond(MoleculePattern _moleculePattern1, ComponentPattern _componentPattern1, MoleculePattern _moleculePattern2, ComponentPattern _componentPattern2) { moleculePattern1 = _moleculePattern1; componentPattern1 = _componentPattern1; moleculePattern2 = _moleculePattern2; componentPattern2 = _componentPattern2; }
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(Molecule _molecule) { if (!_molecule.definition.Equals(moleculeDef)) { //Debug.Log( "molecules don't match" ); return(false); } ComponentPattern otherComponentPattern; Dictionary <ComponentPattern, int> thisComponentsInState = new Dictionary <ComponentPattern, int>(); Dictionary <ComponentPattern, int> otherComponentsInState = new Dictionary <ComponentPattern, int>(); foreach (string componentName in componentPatterns.Keys) { if (!_molecule.components.ContainsKey(componentName)) //does this type of component exist in the molecule? { //Debug.Log( "component " + componentName + " doesn't exist in molecule" ); 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 (MoleculeComponent otherComponent in _molecule.components[componentName]) //how many of the molecule's components are in each state? { otherComponentPattern = new ComponentPattern(otherComponent); if (!otherComponentsInState.ContainsKey(otherComponentPattern)) { otherComponentsInState[otherComponentPattern] = 1; } else { otherComponentsInState[otherComponentPattern]++; } } foreach (ComponentPattern thisComponentPattern in thisComponentsInState.Keys) //does the molecule 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 void SetToProductState(MoleculePattern productMolecule, ComponentPattern productComponent) { productComponent.SetStateOfComponent(this); stateWasUpdated = true; molecule.SetToProductState(productMolecule); }