def test_ring_count(): # Two rings fused = pmd.load_file(get_fn('fused.mol2'), structure=True) top, _ = generate_topology(fused) rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R2]') match_indices = list(rule.find_matches(top)) for atom_idx in (3, 4): assert atom_idx in match_indices assert len(match_indices) == 2 rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R1]') match_indices = list(rule.find_matches(top)) for atom_idx in (0, 1, 2, 5, 6, 7, 8, 9): assert atom_idx in match_indices assert len(match_indices) == 8 # One ring ring = pmd.load_file(get_fn('ring.mol2'), structure=True) top, _ = generate_topology(ring) rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R1]') match_indices = list(rule.find_matches(top)) for atom_idx in range(6): assert atom_idx in match_indices assert len(match_indices) == 6
def test_ring_count(): # Two rings fused = pmd.load_file(get_fn('fused.mol2'), structure=True) top, _ = generate_topology(fused) rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R2]') match_indices = list(rule.find_matches(top)) for atom_idx in (3, 4): assert atom_idx in match_indices assert len(match_indices) == 2 rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R1]') match_indices = list(rule.find_matches(top)) for atom_idx in (0, 1, 2, 5, 6, 7, 8, 9): assert atom_idx in match_indices assert len(match_indices) == 8 # One ring ring = pmd.load_file(get_fn('ring.mol2'), structure=True) top, _ = generate_topology(ring) rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R1]') match_indices = list(rule.find_matches(top)) for atom_idx in range(6): assert atom_idx in match_indices assert len(match_indices) == 6
def test_lazy_cycle_finding(): mol2 = pmd.load_file(get_fn('ethane.mol2'), structure=True) top, _ = generate_topology(mol2) rule = SMARTSGraph(smarts_string='[C]') list(rule.find_matches(top)) assert not any([hasattr(a, 'cycles') for a in top.atoms()]) ring_tokens = ['R1', 'r6'] for token in ring_tokens: rule = SMARTSGraph(smarts_string='[C;{}]'.format(token)) list(rule.find_matches(top)) assert all([hasattr(a, 'cycles') for a in top.atoms()])
def test_lazy_cycle_finding(): mol2 = pmd.load_file(get_fn('ethane.mol2'), structure=True) top, _ = generate_topology(mol2) rule = SMARTSGraph(smarts_string='[C]') list(rule.find_matches(top)) assert not any([hasattr(a, 'cycles') for a in top.atoms()]) ring_tokens = ['R1', 'r6'] for token in ring_tokens: rule = SMARTSGraph(smarts_string='[C;{}]'.format(token)) list(rule.find_matches(top)) assert all([hasattr(a, 'cycles') for a in top.atoms()])
def test_ring_count(): # Two rings fused = pmd.load_file(get_fn('fused.mol2'), structure=True) top, _ = generate_topology(fused) typemap = { atom.index: { 'whitelist': set(), 'blacklist': set(), 'atomtype': None } for atom in top.atoms() } rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R2]', typemap=typemap) match_indices = list(rule.find_matches(top, typemap)) for atom_idx in (3, 4): assert atom_idx in match_indices assert len(match_indices) == 2 rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R1]', typemap=typemap) match_indices = list(rule.find_matches(top, typemap)) for atom_idx in (0, 1, 2, 5, 6, 7, 8, 9): assert atom_idx in match_indices assert len(match_indices) == 8 # One ring ring = pmd.load_file(get_fn('ring.mol2'), structure=True) top, _ = generate_topology(ring) typemap = { atom.index: { 'whitelist': set(), 'blacklist': set(), 'atomtype': None } for atom in top.atoms() } rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6;R1]', typemap=typemap) match_indices = list(rule.find_matches(top, typemap)) for atom_idx in range(6): assert atom_idx in match_indices assert len(match_indices) == 6
def test_ring_count(self, smarts_parser): # Two rings fused = pmd.load_file(get_fn("fused.mol2"), structure=True) fused_graph = TopologyGraph.from_parmed(fused) typemap = { atom.idx: {"whitelist": set(), "blacklist": set(), "atomtype": None} for atom in fused.atoms } rule = SMARTSGraph( name="test", parser=smarts_parser, smarts_string="[#6;R2]", typemap=typemap, ) match_indices = list(rule.find_matches(fused_graph, typemap)) for atom_idx in (3, 4): assert atom_idx in match_indices assert len(match_indices) == 2 rule = SMARTSGraph( name="test", parser=smarts_parser, smarts_string="[#6;R1]", typemap=typemap, ) match_indices = list(rule.find_matches(fused_graph, typemap)) for atom_idx in (0, 1, 2, 5, 6, 7, 8, 9): assert atom_idx in match_indices assert len(match_indices) == 8 # One ring ring = pmd.load_file(get_fn("ring.mol2"), structure=True) typemap = { atom.idx: {"whitelist": set(), "blacklist": set(), "atomtype": None} for atom in ring.atoms } ring_graph = TopologyGraph.from_parmed(ring) rule = SMARTSGraph( name="test", parser=smarts_parser, smarts_string="[#6;R1]", typemap=typemap, ) match_indices = list(rule.find_matches(ring_graph, typemap)) for atom_idx in range(6): assert atom_idx in match_indices assert len(match_indices) == 6
def _rule_match(top, typemap, smart, result): rule = SMARTSGraph( name="test", parser=smarts_parser, smarts_string=smart, typemap=typemap, ) assert bool(list(rule.find_matches(top, typemap))) is result
def _rule_match_count(top, typemap, smart, count): rule = SMARTSGraph( name="test", parser=smarts_parser, smarts_string=smart, typemap=typemap, ) assert len(list(rule.find_matches(top, typemap))) is count
def test_fused_ring(): fused = pmd.load_file(get_fn('fused.mol2'), structure=True) top, _ = generate_topology(fused) rule = SMARTSGraph(name='test', parser=PARSER, smarts_string='[#6]12[#6][#6][#6][#6][#6]1[#6][#6][#6][#6]2') match_indices = list(rule.find_matches(top)) assert 3 in match_indices assert 4 in match_indices assert len(match_indices) == 2
def test_fused_ring(): fused = pmd.load_file(get_fn('fused.mol2'), structure=True) top, _ = generate_topology(fused) rule = SMARTSGraph( name='test', parser=PARSER, smarts_string='[#6]12[#6][#6][#6][#6][#6]1[#6][#6][#6][#6]2') match_indices = list(rule.find_matches(top)) assert 3 in match_indices assert 4 in match_indices assert len(match_indices) == 2
def test_lazy_cycle_finding(): mol2 = pmd.load_file(get_fn('ethane.mol2'), structure=True) typemap = { atom.idx: { 'whitelist': set(), 'blacklist': set(), 'atomtype': None } for atom in mol2.atoms } rule = SMARTSGraph(smarts_string='[C]', typemap=typemap) list(rule.find_matches(mol2, typemap)) assert not any(['cycles' in typemap[a.idx] for a in mol2.atoms]) ring_tokens = ['R1', 'r6'] for token in ring_tokens: rule = SMARTSGraph(smarts_string='[C;{}]'.format(token), typemap=typemap) list(rule.find_matches(mol2, typemap)) assert all(['cycles' in typemap[a.idx] for a in mol2.atoms])
def test_lazy_cycle_finding(): mol2 = pmd.load_file(get_fn('ethane.mol2'), structure=True) top, _ = generate_topology(mol2) typemap = { atom.index: { 'whitelist': set(), 'blacklist': set(), 'atomtype': None } for atom in top.atoms() } rule = SMARTSGraph(smarts_string='[C]', typemap=typemap) list(rule.find_matches(top, typemap)) #assert not any([hasattr(a, 'cycles') for a in top.atoms()]) assert not any(['cycles' in typemap[a.index] for a in top.atoms()]) ring_tokens = ['R1', 'r6'] for token in ring_tokens: rule = SMARTSGraph(smarts_string='[C;{}]'.format(token), typemap=typemap) list(rule.find_matches(top, typemap)) #assert all([hasattr(a, 'cycles') for a in top.atoms()]) assert all(['cycles' in typemap[a.index] for a in top.atoms()])
def read_search_mapping(search_mapping_filename, user_mapping_filename, topology): """Read the search mapping xml file Parameters ---------- search_mapping_filename : str Name of xml file containing ordered search parameters user_mapping_filename : str Name of xml file containing molecules in the system topology : mdTraj.Topology Topology object (to be expanded) """ # root = ET.fromstring(open(search_mapping_filename).read()) searchlist = [] # list containing all search values ordered by priority searchlist.append("C") searchlist.append("CC") searchlist.append("CCC") # for value in root.findall('value'): # searchlist.append(value.attrib['searchstr']) print("{0:s}: {1}".format("Search String", searchlist)) #root = ET.fromstring(open(user_mapping_filename).read()) molecules = [] for molecule in root.findall('molecule'): molecules.append( molecule.attrib['mol_str']) #smarts string for molecule print("{0:s}: {1}".format("Molecules", molecules)) parser = SMARTSParser() matches = [] for searchstr in searchlist: print(searchstr) graph = SMARTSGraph(searchstr, parser=parser) i = graph.find_matches(topology) matches.append(list(i)) print(matches) return matches
def test_fused_ring(self, smarts_parser): mol2 = pmd.load_file(get_fn("fused.mol2"), structure=True) mol2_graph = TopologyGraph.from_parmed(mol2) typemap = { atom.idx: {"whitelist": set(), "blacklist": set(), "atomtype": None} for atom in mol2.atoms } rule = SMARTSGraph( name="test", parser=smarts_parser, smarts_string="[#6]12[#6][#6][#6][#6][#6]1[#6][#6][#6][#6]2", typemap=typemap, ) match_indices = list(rule.find_matches(mol2_graph, typemap)) assert 3 in match_indices assert 4 in match_indices assert len(match_indices) == 2
def test_fused_ring(): mol2 = pmd.load_file(get_fn('fused.mol2'), structure=True) typemap = { atom.idx: { 'whitelist': set(), 'blacklist': set(), 'atomtype': None } for atom in mol2.atoms } rule = SMARTSGraph( name='test', parser=PARSER, smarts_string='[#6]12[#6][#6][#6][#6][#6]1[#6][#6][#6][#6]2', typemap=typemap) match_indices = list(rule.find_matches(mol2, typemap)) assert 3 in match_indices assert 4 in match_indices assert len(match_indices) == 2
def _rule_match_count(top, smart, count): rule = SMARTSGraph(name='test', parser=PARSER, smarts_string=smart) assert len(list(rule.find_matches(top))) is count
def _rule_match(top, smart, result): rule = SMARTSGraph(name='test', parser=PARSER, smarts_string=smart) assert bool(list(rule.find_matches(top))) is result
def _rule_match_count(top, smart, count): rule = SMARTSGraph(name='test', parser=PARSER, smarts_string=smart) assert len(list(rule.find_matches(top))) is count
def _rule_match(top, smart, result): rule = SMARTSGraph(name='test', parser=PARSER, smarts_string=smart) assert bool(list(rule.find_matches(top))) is result