-
Notifications
You must be signed in to change notification settings - Fork 38
Add some topology slicing methods. #961
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
Draft
chrisjonesBSU
wants to merge
12
commits into
mosdef-hub:main
Choose a base branch
from
chrisjonesBSU:calc-charges
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.
Draft
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f50a9b5
Add slicing methods, set number as option in iter_sites methods
284c88b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cc9045c
Merge branch 'main' into calc-charges
chrisjonesBSU a77202a
Merge branch 'main' of github.com:mosdef-hub/gmso into calc-charges
1ac027a
Merge branch 'main' of github.com:mosdef-hub/gmso into calc-charges
0d02c4a
Add method to convert topology to OpenFF Molecule object
176bb78
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5af78e1
Merge branch 'main' into calc-charges
chrisjonesBSU 7f2f9e7
start charges.py file to calc partial charges
8f946b1
Merge branch 'calc-charges' of github.com:chrisjonesBSU/gmso into cal…
0d96075
Merge branch 'main' of github.com:mosdef-hub/gmso into calc-charges
d7b0755
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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 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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| from gmso.core.topology import Topology | ||
|
|
||
|
|
||
| def slice_topology_by_molecule(topology, molecule_tag, molecule_number=None): | ||
| """Create a Topology that contains a subset of molecules from another Topology. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| topology : gmso.core.topology.Topology | ||
| The gmso Topology to perform the slice on | ||
| molecule_tag : str | ||
| The name of the gmso.abstract_site.Molecule object to include in the slice | ||
| molecule_number : int, default None | ||
| If given, only include a single molecule's sites | ||
| If None, then all sites in every molecule matching `molecule_tag` are included | ||
| in the sliced topology. | ||
|
|
||
| Returns | ||
| ------- | ||
| gmso.core.topology.Topology | ||
| A new Topology instance containing only sites and connections from matching molecules. | ||
| """ | ||
| sites = [ | ||
| s | ||
| for s in topology.iter_sites_by_molecule( | ||
| molecule_tag=molecule_tag, molecule_number=molecule_number | ||
| ) | ||
| ] | ||
| return slice_by_sites(topology=topology, sites=sites) | ||
|
|
||
|
|
||
| def slice_topology_by_residue(topology, residue_tag, residue_number=None): | ||
| """Create a Topology that contains a subset of residues from another Topology. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| topology : gmso.core.topology.Topology | ||
| The gmso Topology to perform the slice on. | ||
| residue_tag : str | ||
| The name of the gmso.abstract_site.Residue object to include in the slice. | ||
| residue_number : int, default None | ||
| If given, only include a single residue's sites | ||
| If None, then all sites in every residue matching `residue_tag` are included | ||
| in the sliced topology. | ||
|
|
||
| Returns | ||
| ------- | ||
| gmso.core.topology.Topology | ||
| A new Topology instance containing only sites and connections from matching molecules. | ||
| """ | ||
| sites = [ | ||
| s | ||
| for s in topology.iter_sites_by_residue( | ||
| residue_tag=residue_tag, residue_number=residue_number | ||
| ) | ||
| ] | ||
| return slice_by_sites(topology=topology, sites=sites) | ||
|
|
||
|
|
||
| def slice_by_sites(topology, sites): | ||
| """Used by slice_topology_by_molecule() and slice_topology_by_residue() | ||
|
|
||
| Parameters | ||
| ---------- | ||
| sites : list of gmso.core.atom.Atom | ||
| List of sites to include in the sub-topology. | ||
| topology : gmso.core.topology.Topology | ||
| The topology being sliced. | ||
| """ | ||
| new_topology = Topology() | ||
|
|
||
| connections = set() | ||
| for site in sites: | ||
| new_topology.add_site(site) | ||
| for connection in topology.iter_connections_by_site(site): | ||
| connections.add(connection) | ||
|
|
||
| for connection in connections: | ||
| new_topology.add_connection(connection) | ||
|
|
||
| return new_topology |
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.
Uh oh!
There was an error while loading. Please reload this page.