Skip to content

Commit

Permalink
Fixes case where multiple monomers have the same MW
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
jlaw9 committed Aug 6, 2024
1 parent 647bd55 commit 1854f77
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions m2p/polymaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,14 @@ def get_monomers(
monomers == None
# Sort by MW
if sort_by_mw == True:
dict_mw_smile = {
Descriptors.ExactMolWt(Chem.MolFromSmiles(Chem.CanonSmiles(s))): s
# use a list of tuples instead of a dicitonary
# in case there are monomers with the same molecular weight
list_mw_smile = [
(Descriptors.ExactMolWt(Chem.MolFromSmiles(Chem.CanonSmiles(s))), s)
for s in monomers
}
monomers = tuple(dict_mw_smile[k] for k in sorted(dict_mw_smile))
]
monomers = tuple(s for mw, s in sorted(list_mw_smile,
key=lambda x: x[0]))

return monomers

Expand Down

0 comments on commit 1854f77

Please sign in to comment.