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 function to create ions from AMBER templates #210

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

lohedges
Copy link
Contributor

This PR adds simple functions for creating Na+ and Cl- ions using AMBER template files. The idea is to use these in BioSimSpace and SOMD2 to provide templates for alchemical ion pertubations. For example, something like:

import BioSimSpace as BSS
import sire as sr

# Here we have a system called mols that contains a single perturbable molecule (molecule 0) and waters.

# First, find the furthers water from the perturbable molecule.
water = mols["furthest water from molidx 0"]

# Create an ion using the same coordinates as the oxygen (atom 0).
ion = sr.legacy.IO.createChlorineIon(water[0].coordinates(), "tip3p")

# Merge the water and ion. I'd do this directly in Sire, but the default alignment currently fails 
# with:
#     RuntimeError: SireError::program_bug: Attempt to find the alignment matrix failed to produce a
#     valid rotation matrix. Determinant should be 1. It is equal to 0.
# Will need to resolve this.
mapping = BSS.Align.matchAtoms(
    BSS._SireWrappers.Molecule(water),
    BSS._SireWrappers.Molecule(ion),
    scoring_function="rmsd_flex_align"
)
merged = BSS.Align.merge(
    BSS._SireWrappers.Molecule(water),
    BSS._SireWrappers.Molecule(ion),
    mapping=mapping
)

# Replace the water with the perturbable molecule.
mols.remove(water)
mols.add(merged._sire_object)

The ion information is so minimal that we could probably store the template another way if we wished to preserve space. This just mimics the approach used for the water topologies and gives the option of using parameters optimised for the typical water models that we use (can add more in future). I could also consolidate the two functions to call a common _pvt_create_ion function, or similar. However, they were so short that I didn't think it was worth the effort.

  • I confirm that I have merged the latest version of devel into this branch before issuing this pull request (e.g. by running git pull origin devel): [y]
  • I confirm that I have added a test for any new functionality in this pull request: [y]
  • I confirm that I have added documentation (e.g. a new tutorial page or detailed guide) for any new functionality in this pull request: [y]
  • I confirm that I have added a changelog entry to the changelog (we will add a link to this PR as part of the review): [y]
  • I confirm that I have permission to release this code under the GPL3 license: [y]

Suggested reviewers:

@chryswoods

@jmichel80
Copy link
Contributor

I think there aren’t enough degrees of freedom in a monoatomic ion for the alignment algorithm to work.

@lohedges
Copy link
Contributor Author

Yes, exactly. I think we should have some option to support this, though, i.e. detect an ion and just replace the coordinates with those of the mapped atom rather than attempting to align. The issue here is that we use the alignment when scoring the mappings, so it's performed by default.

Copy link
Contributor

@chryswoods chryswoods left a comment

Choose a reason for hiding this comment

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

Looks good - nice to have this functionality.

@lohedges lohedges merged commit 3c890c3 into devel Jul 11, 2024
5 checks passed
@lohedges lohedges deleted the feature_ion_template branch July 11, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants