Source code for schrodinger.test.stu.outcomes.smarts_check

import sys
import warnings

from schrodinger import structure
from schrodinger.structutils import analyze


[docs]def assert_ct_smarts(ct: structure.Structure, asl: str, desired_smarts: str, title: str): """ Assert that SMARTS pattern matches the ASL substructure. :param ct: Structure to perform matches on :param asl: Pattern to do a substructure extraction. :param desired_smarts: SMARTS pattern :param title: title of Structure for error reporting :raises AssertionError: On SMARTS mismatch. """ # Check to see if the chemistry is correct alist = analyze.evaluate_asl(ct, asl) this_ct = ct.extract(alist) # BLDMGR-4655 replace with rdkit with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning, message="analyze.evaluate_smarts") if not analyze.evaluate_smarts(this_ct, desired_smarts): raise AssertionError("SMARTS pattern not correct in %s\n " % title + "--Desired %s " % desired_smarts + "--Actual %s " % analyze.generate_smarts_canvas(this_ct))
[docs]def smarts_check(asl, smarts, *fns): """ Return a failure if ANY frame in the filename does not have any atoms that match the asl expression OR if the atoms that match the asl expression do not also match the smarts pattern. :param asl: An asl expression for a region :param smarts: A smarts expression :param fns: Filenames of any maestro structure files Command line usage: $SCHRODINGER/run smarts_check.py <asl> <smarts> <filename(s)> """ errors = [] for fn in fns: for ict, ct in enumerate(structure.StructureReader(fn)): try: assert_ct_smarts(ct, asl, smarts, fn + ":%d" % (ict + 1)) except AssertionError as err: errors.append(str(err)) if errors: raise AssertionError('\n'.join(errors)) return True
if __name__ == "__main__": if smarts_check(*sys.argv[1:]): print("PASS") else: print("FAIL")