private int CountBoundMultiplicity(List <AtomBehavior> atoms, AtomBehavior atom) { int count = 0; foreach (AtomBehavior currentAtom in atoms) { if (currentAtom == atom) { count++; } } Debug.Log("CountBoundMultiplicity : " + atom); Debug.Log("CountBoundMultiplicity : " + count); return(count); }
private List <AtomBehavior> GetStartingPointsByType(GameObject[] molecule, AtomType symbol) { List <AtomBehavior> atomsFound = new List <AtomBehavior>(); foreach (GameObject atom in molecule) { AtomBehavior atomScript = atom.GetComponent <AtomBehavior>(); if (atomScript.Symbol == symbol) { atomsFound.Add(atomScript); } } Debug.Log("GetStartingPointsByType size : " + atomsFound.Count); return(atomsFound); }
private bool CompareBranchFrom(ref string smiles, AtomBehavior startingPoint) { Debug.Log("CompareBranchFrom current smiles : " + smiles); // First, we record the SMILES' last state to restore it if this branch does not match string smilesLastState = string.Copy(smiles); // We also keep track of the processed atoms in this branch to clear them at the end if it does not match List <AtomBehavior> atomsTrack = new List <AtomBehavior>(); startingPoint.Mark(); atomsTrack.Add(startingPoint); List <AtomBehavior> nonMarkedNeighboursOfInterest; AtomType nextSymbol = AtomType.Void; while (!smiles.Equals("") && smiles[0] != ')') { Debug.Log("In while loop : smiles is ." + smiles + "."); Debug.Log("CompareBranchFrom : the smiles is not empty, entering the while loop"); // an opening parenthesis means a new branch if (smiles[0] == '(') { smiles = smiles.Substring(1); // the method is called recursively for each new branch if (!CompareBranchFrom(ref smiles, startingPoint)) { smiles = string.Copy(smilesLastState); ResetAllMarks(atomsTrack); return(false); } } else { if (smiles[0] == '=') { smiles = smiles.Substring(1); nextSymbol = GetSmilesStartingSymbol(ref smiles); nonMarkedNeighboursOfInterest = startingPoint.GetNonMarkedNeighboursByBondType(2); } else if (smiles[0] == '#') { smiles = smiles.Substring(1); nextSymbol = GetSmilesStartingSymbol(ref smiles); nonMarkedNeighboursOfInterest = startingPoint.GetNonMarkedNeighboursByBondType(3); } else { nextSymbol = GetSmilesStartingSymbol(ref smiles); nonMarkedNeighboursOfInterest = startingPoint.GetNonMarkedNeighboursOfInterest(); } Debug.Log("In while loop : nb of NoI is " + nonMarkedNeighboursOfInterest.Count); if (nonMarkedNeighboursOfInterest.Count == 1 && nonMarkedNeighboursOfInterest[0].Symbol == nextSymbol) { startingPoint = nonMarkedNeighboursOfInterest[0]; startingPoint.Mark(); atomsTrack.Add(startingPoint); } else { smiles = string.Copy(smilesLastState); ResetAllMarks(atomsTrack); return(false); } } } // if we are at the end of the branch and there are more neighbours of interest to be processed (i.e. unmarked)... nonMarkedNeighboursOfInterest = startingPoint.GetNonMarkedNeighboursOfInterest(); Debug.Log("CompareBranchFrom non marked NoI size : " + nonMarkedNeighboursOfInterest.Count); if (nonMarkedNeighboursOfInterest.Count > 0) { Debug.Log("CompareBranchFrom : there are non marked NoI"); // ...the SMILES does not match the current branch smiles = string.Copy(smilesLastState); ResetAllMarks(atomsTrack); foreach (AtomBehavior atom in atomsTrack) { Debug.Log("Atom marked : " + atom.isMarked()); } return(false); } if (!smiles.Equals("")) { smiles = smiles.Substring(1); } // else, the SMILES does match the current branch return(true); }