-
Notifications
You must be signed in to change notification settings - Fork 44
membrane CLI support #1896
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
Open
atravitz
wants to merge
22
commits into
main
Choose a base branch
from
membrane_cli_prototype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
membrane CLI support #1896
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
961dea4
initial cli ideas
atravitz 379fc23
clean up names
atravitz e1fc4ae
add test
atravitz 6f9b292
update docstrings and fix imports
atravitz 595e096
fix tests
atravitz ba74d57
use gufe gzip branch
atravitz 772440f
clean up fixtures
atravitz f367b8e
update fixtures
atravitz 339ef68
adding membrane component to tests
atravitz f955c2d
add membrane barostat check
atravitz 7d09cb2
make output more consistent and add membrane args test
atravitz 637d0b5
error messages
atravitz ea0d6be
revert some out of scope typing things
atravitz 48585cd
tidying fixtures
atravitz 7703c14
update protein arg parsing
atravitz 14ff99c
clearer var naming
atravitz 239e3ac
add protein validate
atravitz 5fd87f2
add validation
atravitz 81cb3a4
fix handling for membrane solvents
atravitz 21be311
update docstring
atravitz 038177b
point to membrane tutorial branch
atravitz ca30f83
linking
atravitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "path": "../ExampleNotebooks/membranes/rbfe_membrane_protein.ipynb" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,60 @@ | ||
| # This code is part of OpenFE and is licensed under the MIT license. | ||
| # For details, see https://github.com/OpenFreeEnergy/openfe | ||
|
|
||
| from plugcli.params import NOT_PARSED, MultiStrategyGetter, Option | ||
| import sys | ||
| from typing import Iterable | ||
|
|
||
| import click | ||
| from plugcli.params import Option | ||
|
|
||
| def _load_protein_from_pdb(user_input, context): | ||
| if ".pdb" not in str(user_input): # this silences some stderr spam | ||
| return NOT_PARSED | ||
| from openfe import ProteinComponent, ProteinMembraneComponent | ||
|
|
||
| from gufe import ProteinComponent | ||
|
|
||
| try: | ||
| return ProteinComponent.from_pdb_file(user_input) | ||
| except ValueError: # any exception should try other strategies | ||
| return NOT_PARSED | ||
| _PDB_EXT = [".pdb"] | ||
| _PDBX_EXT = [".cif", ".pdbx"] | ||
|
|
||
|
|
||
| def _load_protein_from_pdbx(user_input, context): | ||
| if not any( | ||
| [ext in str(user_input) for ext in [".pdb", ".cif", ".pdbx"]] | ||
| ): # this silences some stderr spam | ||
| return NOT_PARSED | ||
| def _contains_any_substring(input: str, substrings: Iterable[str]) -> bool: | ||
| return any([substring in input for substring in substrings]) | ||
|
|
||
| from gufe import ProteinComponent | ||
|
|
||
| def _load_protein_from_file(input_file, protein_class: ProteinComponent | ProteinMembraneComponent): | ||
| valid_ext = _PDB_EXT + _PDBX_EXT | ||
| if not _contains_any_substring(input_file, valid_ext): | ||
| raise ValueError( | ||
| f"To load a {protein_class.__name__}, the file extension must contain one of: {valid_ext}." | ||
| ) | ||
| try: | ||
| return ProteinComponent.from_pdbx_file(user_input) | ||
| except ValueError: # any exception should try other strategies | ||
| return NOT_PARSED | ||
| if _contains_any_substring(input_file, _PDB_EXT): | ||
| return protein_class.from_pdb_file(input_file) | ||
| elif _contains_any_substring(input_file, _PDBX_EXT): | ||
| return protein_class.from_pdbx_file(input_file) | ||
| except ValueError: | ||
| click.secho(f"Unable to load a {protein_class.__name__} from {input_file}.", err=True) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| get_molecule = MultiStrategyGetter( | ||
| strategies=[ | ||
| _load_protein_from_pdb, | ||
| _load_protein_from_pdbx, | ||
| ], | ||
| error_message="Unable to generate a molecule from '{user_input}'.", | ||
| ) | ||
| # TODO: these functions are shims to work with plugcli. We should consider migrating to just click. | ||
| def _get_protein(user_input, context): | ||
| return _load_protein_from_file(user_input, ProteinComponent) | ||
|
|
||
|
|
||
| def _get_protein_membrane(user_input, context): | ||
| return _load_protein_from_file(user_input, ProteinMembraneComponent) | ||
|
|
||
|
|
||
| PROTEIN = Option( | ||
| "-p", | ||
| "--protein", | ||
| help=("ProteinComponent. Can be provided as an PDB or as a PDBx/mmCIF file. string."), | ||
| getter=get_molecule, | ||
| help=( | ||
| "Path to a PDB or PDBx/mmCIF file containing a protein. Mutually exclusive with --protein-membrane." | ||
| ), | ||
| getter=_get_protein, | ||
| ) | ||
|
|
||
| PROTEIN_MEMBRANE = Option( | ||
| "--protein-membrane", | ||
| help=( | ||
| 'Path to a PDB or PDBx/mmCIF file containing a fully solvated protein-membrane system. Mutually exclusive with --protein. See "Combining System Components into a Single PDB File"' | ||
| ), | ||
| getter=_get_protein_membrane, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(this was an erroneous commit months ago)