-
Notifications
You must be signed in to change notification settings - Fork 107
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
atomate2 / OpenMM OPLS-AA Enhancements #1111
base: main
Are you sure you want to change the base?
Conversation
…haps this is fine? and (2) usused eps14 variable (need to check that eps == eps14)
…tead; solution: comment out eps14 line to match original ligpargen code
… 14 interaction scale values (i.e., 0.5); changed create_system_from_xml to create_ff_from_xml to enable generate_openmm_interchange to have access to combination rules only available via the forcefield...still experiencing NoneType error when creating OpenMMInterchange object which prohibits inspection of OpenMMInterchange in generate_openmm_interchange
… to convert xml to string, leaving this commented for now before checking other cases
…to cutoff; incorporated diffusedxml to follow linter guidelines
… and solution was to .split() command into a list of strings
…rate_opls_xml(...) is complete
… generate OPLS .xml files
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.
Couple comments but generally looks good!
src/atomate2/openmm/jobs/generate.py
Outdated
import warnings | ||
import xml.etree.ElementTree as ET | ||
from pathlib import Path | ||
from xml.etree.ElementTree import tostring | ||
|
||
import defusedxml.ElementTree as DiffET |
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.
Do we need defusedxml in particular? Best to avoid adding a dependency if possible
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.
ruff gave me the following error for ET.parse
,
S314 Using `xml` to parse untrusted data is known to be vulnerable to XML attacks; use `defusedxml` equivalents
I now see that # noqa: S314
was there in the original version to suppress this error, so I've updated the try/except statement, now without defusedxml. I also removed the textwrap dependency.
src/atomate2/openmm/jobs/generate.py
Outdated
lj14 = gen.lj14scale | ||
|
||
system = ff.createSystem(topology.to_openmm(), nonbondedMethod=PME) | ||
if "opls" in tags: |
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.
tags should just be metadata, not core logic. You can add another mixing related kwarg as needed
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.
Good point--I've replaced this behavior with an ff_kwargs
argument to generate_openmm_interchange
.
names_smiles: dict[str, str], output_dir: str | Path, overwrite_files: bool = False | ||
names_params: dict[str, dict[str, str]], |
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.
can you document what params are allowed?
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.
Done.
@@ -19,7 +19,7 @@ | |||
from openff.units import unit | |||
|
|||
|
|||
def test_create_system_from_xml(openmm_data): | |||
def test_ff_system_from_xml(openmm_data): |
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.
-> test_create_ff_from_xml
@janosh all pre-commit/pytests are working on my end as of my last commit, could you try running the tests again? Thanks @orionarcher for the comments! |
@janosh The last failed test is due to an environment variable dependence introduced by the export LPG_IMAGE_NAME="USERNAME/ligpargen:latest"
export CONTAINER_SOFTWARE="podman-hpc" # e.g. Based on what I've observed from the VASP/AIMS tests, I just updated |
Summary
This PR resolves the first two enhancements proposed in Issue #1102:
opls_lj()
I've changed
create_system_from_xml
tocreate_ff_from_xml
insrc/atomate2/openmm/jobs/generate.py
. Why? The OPLS geometric combination rules have two requirements, (1) aCustomNonbondedForce
in OpenMM that combines thesigma
andeps
parameters geometrically, and (2) thecoulomb14scale
andlj14scale
attributes of theForceField
are both0.5
. The latter was enough justification for raising an error if not the case--to do so, theForceField
object would need to be accessible ingenerate_openmm_interchange
(instead of adding unsuitable arguments tocreate_system_from_xml
). Originally,create_system_from_xml
created both theForceField
andSystem
within the same function; now,system
andff
are separate variables ingenerate_openmm_interchange
.generate_opls_xml()
via LigParGen and BOSS source code directly. To do so, users would need to follow the steps in the docs from this fork.Currently,
generate_opls_xml
is only functional so long as the user has a local installation of Docker and created a private (for now, pending approval for pushing to public registriesapproval received to save on public registries) image of LigParGen. The documentation is provided to completion indocs/user/codes/openmm.md
.EDIT: We've received written approval from Dr. William Jorgensen to host the LigParGen image on a public registry, i.e., the user no longer has to build this themself.
download_opls_xml
Function #1054 have been merged into this fork (i.e., extending thedownload_opls_xml
to handle charges, number of optimization iterations, and charge method).Additional dependencies introduced
defusedxml, resolves ruff failures for safely loading XML files, e.g.,textwrap, enables easier text wrapping of long warnings/errors printed for the user, e.g.,Checklist
The easiest way to handle this is to run the following in the correct sequence on
your local machine. Start with running
ruff
andruff format
on your new code. This willautomatically reformat your code to PEP8 conventions and fix many linting issues.
Run ruff on your code.
type check your code.
CC'ing @utf, @orionarcher