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

add small molecule charge change support with test #973

Merged
merged 6 commits into from May 5, 2022
Merged

Conversation

dominicrufa
Copy link
Contributor

Description

add small-molecule charge change support and attempt to generalize the existing protein mutation charge change functionality to avoid code duplication

Motivation and context

adds this support

How has this been tested?

performs a RelativeFEPSetup on two Bace ligands with unequal charge, performs energy validation and asserts both systems are neutral after modification

@ijpulidos ijpulidos added the priority: high priority high label Mar 21, 2022
@zhang-ivy
Copy link
Contributor

zhang-ivy commented Mar 22, 2022

@dominicrufa : Looks like the tests are failing for this -- can you fix the errors and make sure you run the relevant tests locally with pytest before pushing again?

@zhang-ivy
Copy link
Contributor

zhang-ivy commented Mar 22, 2022

I just reviewed. It mostly looks good, but I find the locations of all the helper functions confusing:

  • _get_charge_difference(current_oemol, new_oemol) and get_water_indices(charge_diff, new_positions, new_topology, radius=0.8): are present in SmallMoleculeSetProposalEngine
  • _get_charge_difference(current_resname, new_resname) is in PolymerProposalEngine
  • modify_atom_classes(water_atoms, topology_proposal): is just placed at the bottom of topology_proposal.py
  • get_ion_and_water_parameters(system, topology, positive_ion_name="NA", negative_ion_name="CL", water_name="HOH") and transform_waters_into_ions(water_atoms, system, charge_diff, particle_parameter_dict) are in perses/utils/smallmolecules.py

Why don't we just place all these helper functions in a new file called utils/charge_changing.py (or something like this)? None of the helper functions actually require any SmallMoleculeSetProposalEngine/PolymerProposalEngine class attributes, so they can be separated easily. I also don't think it makes sense to require that the PointMutationExecutor import SmallMoleculeSetProposalEngine , as would be required by the current implementation.

@jchodera
Copy link
Member

One other thing to note here is that once biopolymer support is added to OpenFF, we can take another pass at overhauling and simplifying this code substantially: We will simply be able to compute the total charge of the Molecule or Topology and adjust accordingly. So it may not be worthwhile to spend too much time refactoring at this stage.

@jchodera
Copy link
Member

jchodera commented Apr 1, 2022

@dominicrufa : Just a reminder that we'd love to finish this up if possible!

topology_proposal.new_topology.residue_topology.name)
if charge_diff != 0: # then handle this.
new_water_indices_to_ionize = get_water_indices(charge_diff = charge_diff,
new_positions = new_positions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_positions = new_positions,
new_positions = new_positions,

if charge_diff != 0: # then handle this.
new_water_indices_to_ionize = get_water_indices(charge_diff = charge_diff,
new_positions = new_positions,
new_topology = topology_proposal.new_topology,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_topology = topology_proposal.new_topology,
new_topology = topology_proposal.new_topology,

new_water_indices_to_ionize = get_water_indices(charge_diff = charge_diff,
new_positions = new_positions,
new_topology = topology_proposal.new_topology,
radius=0.8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
radius=0.8)
radius=0.8)

charge_diff = get_charge_difference(self._ligand_oemol_old, self._ligand_oemol_new)
if charge_diff != 0: # then handle this.
new_water_indices_to_ionize = get_water_indices(charge_diff = charge_diff,
new_positions = new_positions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_positions = new_positions,
new_positions = new_positions,

if charge_diff != 0: # then handle this.
new_water_indices_to_ionize = get_water_indices(charge_diff = charge_diff,
new_positions = new_positions,
new_topology = topology_proposal.new_topology,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_topology = topology_proposal.new_topology,
new_topology = topology_proposal.new_topology,

new_water_indices_to_ionize = get_water_indices(charge_diff = charge_diff,
new_positions = new_positions,
new_topology = topology_proposal.new_topology,
radius=0.8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
radius=0.8)
radius=0.8)

@zhang-ivy
Copy link
Contributor

@dominicrufa : Looks good to me! Just added some commit suggestions to improve the formatting.

@ijpulidos ijpulidos self-requested a review April 4, 2022 20:21
@ijpulidos ijpulidos linked an issue May 2, 2022 that may be closed by this pull request
@mikemhenry
Copy link
Contributor

Just 3 tests failing for the same reason:

        # Get the array of water indices (w.r.t. new topology) to turn into ions
>       water_indices = PolymerProposalEngine.get_water_indices(charge_diff = charge_diff_test,
                                                 new_positions = new_pos,
                                                 new_topology = top_proposal._new_topology,
                                                 radius=0.8)
E       AttributeError: type object 'PolymerProposalEngine' has no attribute 'get_water_indices'

perses/tests/test_topology_proposal.py:987: AttributeError

@mikemhenry
Copy link
Contributor

Tests just need to get updated, get_water_indices was a static method for PolymerProposalEngine but now is a bare function in charge utilities

@ijpulidos
Copy link
Contributor

@mikemhenry these changes should be pretty straightforward to do, I'll be making those if that is ok with you all. Just to get this merged as soon as possible.

@mikemhenry
Copy link
Contributor

@ijpulidos go ahead and turn on auto merge for this when you are ready!

@ijpulidos ijpulidos enabled auto-merge (squash) May 5, 2022 17:31
@codecov
Copy link

codecov bot commented May 5, 2022

Codecov Report

Merging #973 (2fa18d6) into main (4901ccb) will increase coverage by 0.06%.
The diff coverage is 93.75%.

@ijpulidos ijpulidos merged commit c9fa0c6 into main May 5, 2022
@ijpulidos ijpulidos deleted the small_mol_charge branch May 5, 2022 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high priority high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for generalized charge changes
5 participants