def test_misc() -> None: dihedral_1 = Dihedral_Fragment("C,C,H|C|C|C,H,H") print(dihedral_1) dihedral_2 = Dihedral_Fragment("C,H,H|C|C|C,C,H") print(dihedral_2) print(dihedral_1 == dihedral_2) dihedral_3 = Dihedral_Fragment(atom_list=(['H', 'H'], 'C', 'C', ['Cl', 'Cl'])) print(dihedral_3) print(dihedral_3 == dihedral_2)
def test_CYP() -> None: for dihedral_angles in TEST_ANGLES: print( str( Dihedral_Fragment(atom_list=(['C', 'H', 'O'], 'C', 'C', ['C', 'H', 'O']), dihedral_angles=dihedral_angles)), ) for dihedral_angles in TEST_ANGLES: print( Dihedral_Fragment( atom_list=(['C', 'H', 'H'], 'C', 'C', ['C', 'H', 'O']), dihedral_angles=dihedral_angles, ), )
def re_pattern_matching_for( pattern: Dihedral_Matching_Pattern, debug: bool = False, metadata: Any = None) -> Callable[[Dihedral_Fragment_Str], bool]: if not (has_substitution_pattern(pattern) or has_regex_pattern(pattern)): return lambda test_string: test_string == str( Dihedral_Fragment(pattern)) else: patterns = [ FORMAT_UNESCAPED(re_pattern) for re_pattern in re_patterns(pattern, full_regex=True, flavour='re', debug=debug, metadata=metadata) ] def match_pattern_to(test_string): if debug: print(metadata) print(pattern) print(patterns) print(test_string) print( any([ search(match_pattern, test_string) for match_pattern in patterns ])) print() return any([ search(match_pattern, test_string) for match_pattern in patterns ]) return match_pattern_to
def test_canonical_rep() -> None: test_cases = ( ('H,C4,H|SI|C|C2,H,C4', 'C4,H,H|SI|C|C4,C2,H'), # M(SI) > M(C) ('H,C4,H|C|C|C4,H', 'C4,H,H|C|C|C4,H'), #M(C) == M(C), 3 > 2 ('H,C4,H|C|C|C3,H,H', 'C4,H,H|C|C|C3,H,H'), #M(C) == M(C), 3 ==3, 4 > 3 ('O2|C|C|N2,H', 'N2,H|C|C|O2'), # M(O) > M(N) ('F,C4|C|C|O1,N3', 'F,C4|C|C|O1,N3'), # M(F) > M(O) ) for (dihedral_string, solution) in test_cases: print('TEST: {0}'.format(dihedral_string)) answer = str(Dihedral_Fragment(dihedral_string)) assert answer == solution, '"{0}" (answer) != "{1}" (expected)'.format( answer, solution) cyclic_answer = str(Dihedral_Fragment(answer)) assert cyclic_answer == answer, '"{0}" (answer) != "{1}" (expected)'.format( cyclic_answer, answer)
def main(): for (atom_2, atom_3) in combinations_with_replacement(CENTRAL_ATOMS, 2): if is_forbidden_bond((atom_2, atom_3)): continue for (len_neighbours_1, len_neighbours_4) in product(number_neighbours(atom_2), number_neighbours(atom_3)): neighbours_1 = combinations_with_replacement( ATOMS, len_neighbours_1) neighbours_4 = combinations_with_replacement( ATOMS, len_neighbours_4) for a, b in product(neighbours_1, neighbours_4): d = str( Dihedral_Fragment(atom_list=(list(a), atom_2, atom_3, list(b)))) tags = tags_for_dihedral(d) if len(tags) > 0: print(d, tags)
def sql_pattern_matching_for(pattern: Dihedral_Matching_Pattern, matching_field_name: str = 'dihedral_string'): if not (has_substitution_pattern(pattern) or has_regex_pattern(pattern)): return '{matching_field_name}="{pattern}"'.format( matching_field_name=matching_field_name, pattern=Dihedral_Fragment(pattern), ) else: use_full_regex = has_regex_pattern(pattern) all_patterns = re_patterns(pattern, full_regex=use_full_regex, flavour='sql') #patterns = [FORMAT_UNESCAPED(re_pattern) for re_pattern in re_patterns(pattern, full_regex=True, flavour='sql')] return sql_OR([ '{matching_field_name} {sql_operator} "{match_pattern}"'.format( matching_field_name=matching_field_name, sql_operator=('LIKE' if not use_full_regex else 'REGEXP'), match_pattern=match_pattern, ) for match_pattern in all_patterns ])
('thiol', 'J+|C|S|H'), ('thioether', 'J+|C|S|C'), ('disulfide', 'C|S|S|C'), ('sulfinyl', '%|C|S|C,O'), ('sulfonyl', '%|C|S|C,O,O'), ('sulfino', 'C,O|S|O|H'), ('sulfo', 'C,O,O|S|O|H'), ('thiocyanate', 'C|S|C|N'), ('isothiocyanate', 'C|N|C|S'), ('carbonothioyl', '%|J|C|S,J'), # Groups containing phosphorus ('phosphino', '%|C|P|C{2}'), ('phosphono', '%|C|P|O{3}'), ('phosphate', 'C|O|P|O{3}'), # Groups containing boron ('borono', '%|C|B|O{2}'), ) CHEMICAL_GROUPS = list( map( lambda moiety_pattern: (moiety_pattern[0], str(Dihedral_Fragment(dihedral_string=moiety_pattern[1]))), CHEMICAL_GROUPS, )) if __name__ == '__main__': print(CHEMICAL_GROUPS)
def test_cyclic_fragments() -> None: cyclic_fragment = Dihedral_Fragment(atom_list=(['H', 'H', 'C'], 'C', 'C', ['H', 'C', 'H'], [[2, 0, 1]])) print(str(cyclic_fragment)) assert str(cyclic_fragment) == 'C,H,H|C|C|C,H,H|000', cyclic_fragment polycyclic_fragment, answer = Dihedral_Fragment( atom_list=(['H', 'C', 'C'], 'C', 'C', ['C', 'C', 'H'], [[2, 2, 1], [1, 3, 0]])), 'C,C,H|C|C|C,C,H|020,131' print(str(polycyclic_fragment)) assert str(polycyclic_fragment) == answer, '{0} != {1} (expected)'.format( str(polycyclic_fragment), answer, ) print(Dihedral_Fragment(str(polycyclic_fragment))) polycyclic_fragment, answer = Dihedral_Fragment( atom_list=(['H', 'N', 'O'], 'C', 'C', ['C', 'C', 'H'], [[2, 2, 1], [1, 2, 0]])), 'O,N,H|C|C|C,C,H|020,121' print(str(polycyclic_fragment)) assert str(polycyclic_fragment) == answer, '{0} != {1} (expected)'.format( str(polycyclic_fragment), answer, ) print(Dihedral_Fragment(str(polycyclic_fragment))) polycyclic_fragment, answer = Dihedral_Fragment(atom_list=( ['C', 'N', 'O'], 'C', 'C', ['O', 'O', 'O'], [[0, 6, 2], [1, 5, 1], [2, 4, 0]])), 'O,O,O|C|C|O,N,C|040,151,262' print(str(polycyclic_fragment)) assert str(polycyclic_fragment) == answer, '{0} != {1} (expected)'.format( str(polycyclic_fragment), answer, ) polycyclic_fragment, answer = Dihedral_Fragment(atom_list=( ['C', 'N', 'O'], 'C', 'C', ['O', 'O', 'O'], [[0, 6, 2], [1, 5, 2], [2, 4, 2]])), 'O,O,O|C|C|O,N,C|040,051,062' print(str(polycyclic_fragment)) assert str(polycyclic_fragment) == answer, '{0} != {1} (expected)'.format( str(polycyclic_fragment), answer, ) polycyclic_fragment, answer = str( Dihedral_Fragment( 'C,C,C|C|C|C,C,C|002,101,200')), 'C,C,C|C|C|C,C,C|000,101,202' print(str(polycyclic_fragment)) assert str(polycyclic_fragment) == answer, '{0} != {1} (expected)'.format( str(polycyclic_fragment), answer, ) polycyclic_fragment, answer = str( Dihedral_Fragment( 'C,C,N|C|C|C,C,C|002,101,200')), 'N,C,C|C|C|C,C,C|000,101,202' print(str(polycyclic_fragment)) assert str(polycyclic_fragment) == answer, '{0} != {1} (expected)'.format( str(polycyclic_fragment), answer, ) polycyclic_fragment, answer = str( Dihedral_Fragment('C,C,C,C,C|P|P|C,C,C,C,C|004,103,212,311,420') ), 'C,C,C,C,C|P|P|C,C,C,C,C|000,101,212,313,424' print(str(polycyclic_fragment)) assert str(polycyclic_fragment) == answer, '{0} != {1} (expected)'.format( str(polycyclic_fragment), answer, ) try: Dihedral_Fragment('C,C,C|C|C|C,C,C|0100') raise Exception('This should have failed.') except AssertionError: print('Rings length > 9 failed as expected.')
def test_chiral_str() -> None: dihedral_1 = Dihedral_Fragment("C,C,H|C|C|C,H,H") print(dihedral_1.__str__()) print(dihedral_1.__str__(flag_chiral_sides=True))
def test_atom_list_init() -> None: fragment = Dihedral_Fragment(atom_list=(['C'], 'C', 'C', ['C']))