-
Notifications
You must be signed in to change notification settings - Fork 2
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
Resolution layering #13
Conversation
…it is possible that it is the last character
9ce4a45
to
bfea1da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still missing a resolve_all
that just does the thing and returns the final molecule.
You now always increment self.resolution_counter
, which keeps CGsmiles from being fully recursive. The alternative is to see if this resolution did anything, and if not move on to the next layer.
That said, is there any way to write something like this that is not an infinite loop? {[#A]}.{#A=[$][#A][$]}
add edits Co-authored-by: Peter C Kroon <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the relation between fragment_dict and fragment_str?
Co-authored-by: Peter C Kroon <[email protected]>
Code looks good to me. I suggest getting rid of the if len(fragment_dicts) != len(fragment_strs): raise IndexError
self.fragment_dicts = []
for f_dict, f_str in zip(fragment_dicts, fragment_strs):
f_dict = copy(f_dict)
f_dict.update(read_fragments(f_str))
self.fragment_dicts.append(f_dict) |
In the end, I think it makes the most sense to allow fragments to be provided as dict or str. Mixing both leads to all sorts of sanity checks we can avoid. It is so easy to split the string and populate a fragment dict together with some recycled fragments that I don't think this feature is needed. Hence the error message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Can we simplify the __init__
even more by reducing the amount of allowed combinations of arguments? Another option is to have different constructors, e.g. from_fragments
and from_meta_graph
@pckroon possibly but I think it is not worth doing at the moment. 99% of applications will be resolving a cgsmiles string where both fragments and the meta_graph are in the string. For those applications putting stuff in the init is sufficiently easy and takes little python knowledge. The "advanced" API functions of providing a meta_graph or fragment list are mostly for polyply/vermouth. Even there I don't have a real use case yet. Perhaps at some point mapping files can be replaced and then it would make sense having an advanced API. That's quite a bit in the future in my opinion. |
@fgrunewald I refactored the API as suggested using constructors. That is pretty neat. Additionally, one can have more advanced workflows by subclassing and adding a new constructor. I think that is actually even more handy. The only thing I'm now considering is having a simple def resolve(cgsmiles_str, all_atom):
_, molecule = MoleculeResolver.from_string(cgsmiles_str, last_all_atom=all_atom).resolve_all()
return molecule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. Looks very clean this way!
Some comments on the new docstrings.
Co-authored-by: Peter C Kroon <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
Nice work
implements the resolution layering; this is branched off rings_new