def test_complicated_torsion(): """ Test ChemicalEnvironment objects with complicated torsion test methods that add atoms, remove atoms add ORtypes and ANDtypes to existing atoms This is the SMIRK for the final torsion "[*:1] - [#6:2](=[#8,#7;H0]) - [#6:3](-[#7X3,#8X2;+0]-[#1])(-[#1]) - [*:4]" """ torsion_smirks = "[*:1]-[#6:2]-[#6:3]-[*:4]" torsion = ChemicalEnvironment(torsion_smirks) # save atoms (use selectAtom) atom1 = torsion.selectAtom(1) atom2 = torsion.selectAtom(2) atom3 = torsion.selectAtom(3) # Add atoms with names so I can try to remove them atom2alpha = torsion.addAtom(atom2, [('=',[])], None, [('#8',[]),('#7',[])], ['H0']) atom3alpha1 = torsion.addAtom(atom3) atom3beta1 = torsion.addAtom(atom3alpha1, [('-',[])], None, [('#1',[])]) atom3alpha2 = torsion.addAtom(atom3, [('-',[])], None, [('#1',[])]) # Get bond for atom3 and alpha and add ANDtype bond = torsion.getBond(atom3, atom3alpha1) assert bond is not None bond.addORtype('-', []) # Add ORtypes and ANDtypes to atom3 alpha atom atom3alpha1.addORtype('#7', ['X3']) atom3alpha1.addORtype('#8', ['X2']) atom3alpha1.addANDtype('+0') # Call getAtoms and getBonds just to make sure they work torsion.getAtoms() torsion.getBonds() # get smarts and smirks for the large torsion smarts = torsion.asSMIRKS(smarts=True) assert is_valid_smirks(smarts) smirks = torsion.asSMIRKS() assert is_valid_smirks(smirks) # Try removing atoms # if it was labeled: removed = torsion.removeAtom(atom1) assert not removed removed = torsion.removeAtom(atom3alpha1) assert not removed removed = torsion.removeAtom(atom3beta1) assert removed
def isValid(self, smirks=None): """ Returns if the environment is valid, that is if it creates a parseable SMIRKS string. """ if smirks is None: smirks = self._asSMIRKS() from chemper.chemper_utils import is_valid_smirks return is_valid_smirks(smirks)
def test_other_cluster_graph(graph1, graph2): """ Check graphs build successfully by looking at minimal examples """ # check that a duplicate of the graph is treated as identical assert graph1 == graph2 # check that some of the extraction functions work as expected bonds = graph1.get_bonds() atom = graph1.get_atoms()[0] neighbor = graph1.get_neighbors(atom)[0] bond = graph1.get_connecting_bond(atom, neighbor) assert bond is not None # check graph makes a valid smirks assert is_valid_smirks(graph1.as_smirks())
def test_smirks_validity(smirks, is_valid): assert chemper_utils.is_valid_smirks(smirks) == is_valid