marrink-lab / vermouth-martinize

Describe and apply transformation on molecular structures and topologies
Apache License 2.0
86 stars 38 forks source link

Selectively removing interactions from molecule #483

Closed csbrasnett closed 1 year ago

csbrasnett commented 1 year ago

Discussed in https://github.com/marrink-lab/vermouth-martinize/discussions/482

Regarding reading in itps: it would be useful to have read back in header information and meta attributes for different bond groups. The former would be useful for checking aspects of secondary structure assignment, and the latter for itp editing when needed.

Originally posted by **csbrasnett** November 16, 2022 I need to edit an itp to remove parts of the elastic network, as determined by secondary structure assignment. As a minimal example, I would have thought something like this should work: ```python # loop over regions where we want to keep EN for i in wanted_region: # look at all the elastic network interactions for j in all_EN_interactions: # compare atom indicies of the EN interaction to the boundaries of the region we want to keep # if they're within, keep them if all_EN_interactions[j] in wanted_region[i]: continue # if they're outside, remove the interaction else: ff.blocks[molname].remove_interaction('bonds', atoms = all_EN_interactions[j]) ``` However, I keep getting a KeyError `KeyError: "Can't find interaction of type bonds between atoms ['0', '5'] and with version 0"` even though I can definitely see that there's an interaction there. I've tried various versions of the atoms argument in remove_interaction (give as an array, a list, a list of strings, etc.) but none of these seem to work. I guess it might want me to give a version explicitly, but this doesn't seem to work. Perhaps this should be raised as a separate issue, but on this last point when I read in the itp file that's been generated with martinize2, the meta information isn't read back in by vermouth - I think this might be quite a useful feature to have for this sort of purpose?