-
Notifications
You must be signed in to change notification settings - Fork 133
atomate2 / OpenMM OPLS-AA Enhancements #1111
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
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
orionarcher
left a comment
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
| 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` equivalentsI 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.
|
|
||
|
|
||
| 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 |
orionarcher
left a comment
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.
Thanks for addressing my comments, this looks good on my end!
janosh
left a comment
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.
looks good at a cursory glance (not my wheelhouse 😄)
* added opls_lj function; pre-commit fails for (1) eps._value call, perhaps this is fine? and (2) usused eps14 variable (need to check that eps == eps14) * eps14 is not the correct value, off by 0.5 and eps should be used instead; solution: comment out eps14 line to match original ligpargen code * initial commit to implementing opls_lj with error checking for proper 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 * the use of io.StringIO is seemingly a bug? works fine without needing to convert xml to string, leaving this commented for now before checking other cases * added try/except to handle io.StringIO failure * added 1-4 scaling conditional statement; fized opls nonbonded method to cutoff; incorporated diffusedxml to follow linter guidelines * try/except failure should specify selenium or webdriver_manager packages missing * added generate_opls_xml function with placeholder for ligpargen commands * fixed shutil.copy to shutil.move to avoid redundant files in tmpdir * fixed linter issues (namely, subprocess.run(...shell=True) was unsafe and solution was to .split() command into a list of strings * completed OPLS Docker documentation + except for shifter issues, generate_opls_xml(...) is complete * completed boss->ligpargen->docker->podman-hpc->subprocess pipeline to generate OPLS .xml files * minor typo in docs * updated tests for download_ and generate_opls_xml functions * removed defusedxml dependency * removed textwrap dependency * replaced tag-based opls flag to ff_kwargs for opls * added names_params documentation * test_create_ff_from_xml * pre-commit * ff_kwargs is not None * all new tests pass pytest * added monkeypatching env variables * fixed docker and/or podman-hpc edge case * removed rogue file
Summary
This PR resolves the first two enhancements proposed in Issue #1102:
opls_lj()I've changed
create_system_from_xmltocreate_ff_from_xmlinsrc/atomate2/openmm/jobs/generate.py. Why? The OPLS geometric combination rules have two requirements, (1) aCustomNonbondedForcein OpenMM that combines thesigmaandepsparameters geometrically, and (2) thecoulomb14scaleandlj14scaleattributes of theForceFieldare both0.5. The latter was enough justification for raising an error if not the case--to do so, theForceFieldobject would need to be accessible ingenerate_openmm_interchange(instead of adding unsuitable arguments tocreate_system_from_xml). Originally,create_system_from_xmlcreated both theForceFieldandSystemwithin the same function; now,systemandffare 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_xmlis 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_xmlFunction #1054 have been merged into this fork (i.e., extending thedownload_opls_xmlto 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
ruffandruff formaton 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