Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement isomerism bug fixes plus tests #20

Merged
merged 8 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cgsmiles/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ def sort_nodes_by_attr(graph,
attr_dict = nx.get_node_attributes(new_graph, attr)
new_dict = {}
for key, values in attr_dict.items():
try:
iter(values)
except TypeError:
is_list = False
else:
is_list = not isinstance(values, str)
if is_list:
new_values = [mapping[value] for value in values]
else:
new_values = mapping[values]
new_values = mapping[values]
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
new_dict[key] = new_values
if new_dict:
nx.set_node_attributes(new_graph, new_dict, attr)
Expand Down
2 changes: 1 addition & 1 deletion cgsmiles/pysmiles_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def annotate_ez_isomers(molecule):
Parameters
----------
molecule: nx.Graph
The molecule of intrest, which must of ez_isomer_pairs
The molecule of interest, which must of ez_isomer_pairs
and ez_isomer_class set as node attributes
"""
ez_isomer_atoms = nx.get_node_attributes(molecule, 'ez_isomer_atoms')
Expand Down
4 changes: 2 additions & 2 deletions cgsmiles/tests/test_molecule_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ def test_all_atom_resolve_molecule(smile, ref_frags, elements, ref_edges, chiral
meta_mol, molecule = MoleculeResolver.from_string(smile).resolve()

# loop and compare fragments first
counter=0
counter = 0
for node, ref in zip(meta_mol.nodes, ref_frags):
assert meta_mol.nodes[node]['fragname'] == ref[0]
block_graph = meta_mol.nodes[node]['graph']
target_elements = nx.get_node_attributes(block_graph, 'element')
sorted_elements = [target_elements[key] for key in sorted(target_elements)]
print("-->", sorted_elements)
print("-->",ref[1].split())
print("-->", ref[1].split())
assert sorted_elements == ref[1].split()
print(counter)
counter += 1
Expand Down
Loading