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

Implementation of the Martini3 Go-model #550

Merged
merged 102 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
8891cc5
init draft for Go model
fgrunewald Oct 6, 2023
ae818e3
first implementation Go model
fgrunewald Oct 8, 2023
d2ed0f6
implement structural bias processor
fgrunewald Oct 12, 2023
ab9303b
have some handy utilites for the Go pipeline
fgrunewald Oct 12, 2023
b315603
add water bias functionality
fgrunewald Oct 12, 2023
77d7c70
use new contact map format
fgrunewald Oct 12, 2023
96be469
rename get go
fgrunewald Oct 12, 2023
6e05c09
add licensce header
fgrunewald Oct 12, 2023
92fb9b9
move the go_vs_includes
fgrunewald Oct 12, 2023
462d033
add go_pipeline
fgrunewald Oct 12, 2023
01b617b
implement go_pipeline
fgrunewald Oct 12, 2023
f0bc07f
move logging to processor
fgrunewald Oct 12, 2023
1fd451a
lining
fgrunewald Oct 12, 2023
e60e120
refactor topology writing
fgrunewald Oct 13, 2023
e01dc30
some clean up
fgrunewald Oct 13, 2023
b0b4b6c
refactor water bias
fgrunewald Oct 16, 2023
5cd2c82
make water bias workflow worl
fgrunewald Oct 16, 2023
c7eb8c9
baseline for including tests
fgrunewald Oct 16, 2023
f7e4338
working Go flow
fgrunewald Oct 16, 2023
f06b290
contact map tes
fgrunewald Oct 16, 2023
7231e69
Merge branch 'Go' of https://github.com/marrink-lab/vermouth-martiniz…
fgrunewald Oct 16, 2023
257600a
test for reading and error in go map
fgrunewald Oct 16, 2023
4f45d81
test for go utils
fgrunewald Oct 16, 2023
0d7cc94
add test for atomtypes
fgrunewald Oct 16, 2023
90fca98
add test for atomtypes
fgrunewald Oct 16, 2023
31fa775
change name test atomtypes
fgrunewald Oct 16, 2023
b96113e
add tests nonbond_params
fgrunewald Oct 16, 2023
6f59271
fix comment handling
fgrunewald Oct 16, 2023
7e11ddc
use resid function from go_utils
fgrunewald Oct 16, 2023
c072b92
idot safe in resid handling
fgrunewald Oct 16, 2023
cba5f78
update dummy molecule
fgrunewald Oct 16, 2023
7fc412d
topology writing test
fgrunewald Oct 17, 2023
f368a38
do writing test in tmp dir
fgrunewald Oct 17, 2023
82ca6af
address comment in topology file writing
fgrunewald Oct 17, 2023
af6de49
update doc-string
fgrunewald Oct 17, 2023
403ec92
test-water bias
fgrunewald Oct 17, 2023
8ed3e84
refactor water bias test
fgrunewald Oct 17, 2023
f4f97a9
fix go processor chain accounting
fgrunewald Oct 17, 2023
65106b0
test for go processor structure bias
fgrunewald Oct 17, 2023
fbbf8f5
fix indent in vs creator
fgrunewald Oct 17, 2023
71a8d2e
fix some more issues
fgrunewald Oct 17, 2023
cae03e9
adjust test to skip no OV/rCSU contacts
fgrunewald Oct 17, 2023
f01261b
remove debug
fgrunewald Oct 17, 2023
293b73e
add test for symmetric contact
fgrunewald Oct 17, 2023
c87d245
VirtualSideCreator to VirtualSiteCreator
Lp0lp Oct 19, 2023
662ecfa
Moved create_sys_all_attrs to helperfunctions
Lp0lp Oct 19, 2023
56c87bb
move test_molecule to helper_functions
Lp0lp Oct 19, 2023
0056f7f
More fixes
Lp0lp Oct 19, 2023
6ee5107
Merge pull request #555 from Lp0lp/Go
fgrunewald Oct 19, 2023
7a85e44
Keep only symmetrical go contacts.
Lp0lp Oct 20, 2023
7adc157
Fix go_struct_bias tests & add some more.
Lp0lp Oct 20, 2023
6e361d2
use _old_resid in water bias for identifying ID regions
fgrunewald Oct 23, 2023
7f00195
add nx to go_pipeline
fgrunewald Oct 23, 2023
82df118
use _old_resid in structure bias for finding the atomtype
fgrunewald Oct 23, 2023
47cf186
Merge branch 'Go' of https://github.com/marrink-lab/vermouth-martiniz…
fgrunewald Oct 23, 2023
546ac15
Merge branch 'master' into Go
fgrunewald Oct 25, 2023
28359a0
test self interaction nb params
fgrunewald Oct 27, 2023
3182111
add tests for high level errors in water generatoin
fgrunewald Nov 1, 2023
24662f8
remove unneccesary post_section_lines feature
fgrunewald Nov 1, 2023
2f48e61
radd calls to super for run_system
fgrunewald Nov 1, 2023
2b5853c
radd calls to super for run_system
fgrunewald Nov 1, 2023
01483d4
Apply suggestions from code review
fgrunewald Nov 3, 2023
23323a3
properly implement renaming of convert_sigma_to_epsilon
fgrunewald Nov 3, 2023
e535717
add test for go utilitz error
fgrunewald Nov 3, 2023
54ba9d9
more tests
fgrunewald Nov 3, 2023
f66d202
more tests water bias
fgrunewald Nov 3, 2023
7d0727e
fix docstring
fgrunewald Nov 3, 2023
e3cf4ad
loop over lines from buffer when reading contact map
fgrunewald Nov 3, 2023
a1c52ba
address some comments
fgrunewald Nov 3, 2023
bd785f4
fix docstring
fgrunewald Nov 3, 2023
cb223e5
Added go suport in tests. First GO integ test.
Nov 23, 2023
89c292d
Added more integ tests.
Nov 23, 2023
9f4cb17
use -go for map parsing
fgrunewald Nov 30, 2023
911b3a6
fix docs
fgrunewald Nov 30, 2023
23138d6
Update vermouth/processors/water_bias.py
fgrunewald Dec 5, 2023
f31201b
Update vermouth/processors/water_bias.py
fgrunewald Dec 5, 2023
486c13e
Update martinize2_workflow.rst
fgrunewald Dec 5, 2023
b6ca0a1
add doi for c-code
fgrunewald Dec 5, 2023
1699276
fix docs according to new go
fgrunewald Dec 5, 2023
507b36c
Merge branch 'master' into Go
fgrunewald Dec 5, 2023
dacbdf8
Create __init__.py
fgrunewald Dec 5, 2023
6e8382d
Update contact_map.py
fgrunewald Dec 5, 2023
806d1f5
Fix sphinx references
pckroon Dec 5, 2023
6f0f20b
Fix sphinx references
pckroon Dec 5, 2023
0f31eed
fix CLI typo
pckroon Dec 6, 2023
71f19aa
Update bin/martinize2
fgrunewald Dec 6, 2023
317f813
Apply suggestions from code review
fgrunewald Dec 11, 2023
484f904
Apply suggestions from code review
fgrunewald Dec 11, 2023
372f226
Apply suggestions from code review
fgrunewald Dec 11, 2023
01b32b5
Update vermouth/tests/rcsu/test_go_utils.py
fgrunewald Dec 14, 2023
023e457
Update vermouth/tests/helper_functions.py
fgrunewald Dec 14, 2023
cf40022
Update vermouth/tests/rcsu/test_go_structure_bias.py
fgrunewald Dec 14, 2023
aaf8ee2
Update vermouth/tests/integration_tests/test_integration.py
fgrunewald Dec 14, 2023
69ae011
Update vermouth/tests/integration_tests/test_integration.py
fgrunewald Dec 14, 2023
393e1bb
put comment
fgrunewald Dec 14, 2023
72a3817
fix docstring go vs includes
fgrunewald Dec 14, 2023
e2491d0
fix spelling
fgrunewald Dec 14, 2023
012c1c9
Merge branch 'master' into Go
pckroon Dec 14, 2023
2a36e63
make itp_paths dict in write_gmx_topology
fgrunewald Dec 14, 2023
daa792b
fix error type in test
fgrunewald Dec 14, 2023
f5f5dea
fix bug in topology regarding itp_paths
fgrunewald Dec 14, 2023
2fb2821
fix bug in topology regarding itp_paths
fgrunewald Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions bin/martinize2
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def entry():
print(", ".join(known_force_fields[args.to_ff].modifications))
parser.exit()

if args.elastic and args.govs_includes:
if args.elastic and args.go:
parser.error(
"A rubber band elastic network and GoMartini are not "
"compatible. The -elastic and -govs-include flags cannot "
Expand Down Expand Up @@ -953,15 +953,13 @@ def entry():
LOGGER.info("Reading Go model contact map.", type="step")
go_map = read_go_map(args.go_map)
LOGGER.info("Generating the Go model.", type="step")
GoPipeline(moltype=args.govs_moltype,
contact_map=go_map,
cutoff_short=args.go_low,
cutoff_long=args.go_up,
go_eps=args.go_eps,
res_dist=args.go_res_dist,
prefix=args.govs_moltype,
res_graph=res_graph,
).run_system(system)
GoPipeline.run_system(system,
moltype=args.govs_moltype,
contact_map=go_map,
cutoff_short=args.go_low,
cutoff_long=args.go_up,
go_eps=args.go_eps,
res_dist=args.go_res_dist,)
pckroon marked this conversation as resolved.
Show resolved Hide resolved

defines = ("GO_VIRT",)
itp_paths = ["go_atomtypes.itp", "go_nbparams.itp"]
Expand Down
28 changes: 21 additions & 7 deletions vermouth/gmx/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@
a1, a2 = nb_params.atoms
# self interaction
else:
a1 = nb_params.atoms[0]
a2 = nb_params.atoms[0]

Check warning on line 96 in vermouth/gmx/topology.py

View check run for this annotation

Codecov / codecov/patch

vermouth/gmx/topology.py#L95-L96

Added lines #L95 - L96 were not covered by tests

if C6C12:
nb1, nb2 = convert_sigma_epsilon(nb_params.sigma, nb_params.epsilon)
else:
nb1, nb2 = nb_params.sigma, nb_params.epsilon

comments = ";" + " ".join(nb_params.meta['comment'])
if nb_params.meta.get('comment'):
comments = ";" + " ".join(nb_params.meta['comment'])
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
else:
comments = ""
itp_file.write(f"{a1} {a2} 1 {nb1:3.8F} {nb2:3.8F} {comments}\n")

def write_gmx_topology(system, top_path, itp_paths=[], C6C12=False, defines=(), header=()):
Expand All @@ -119,21 +122,32 @@
system: :class:vermouth.System
top_path: pathlib.Path
path for topology file
itp_paths: list[pathlib.Path]
list of paths for writing the topology parameters
like atomtypes.
C6C12: bool
write non-bonded interaction parameters using LJ
C6C12 form
defines: tuple(str)
define statments to include in the topology
header: tuple(str)
any comment lines to include at the beginning
"""
if not system.molecules:
raise ValueError("No molecule in the system. Nothing to write.")

Check warning on line 137 in vermouth/gmx/topology.py

View check run for this annotation

Codecov / codecov/patch

vermouth/gmx/topology.py#L137

Added line #L137 was not covered by tests

itp_paths = itp_paths[::-1]
include_string = ""
# First we write the atomtypes and nonbondparams directive
if itp_paths:
write_atomtypes(system, itp_paths[0], C6C12)
write_nonbond_params(system, itp_paths[1], C6C12)
include_string = "\n".join('#include "{}"'.format(path) for path in itp_paths[:2])
include_string += "\n"
# First we write the atomtypes directive
if "atomtypes" in system.gmx_topology_params:
_path = itp_paths.pop()
write_atomtypes(system, _path, C6C12)
include_string += f'\n #include "{_path}"'
# Next we write the nonbond_params directive
if "nonbond_params" in system.gmx_topology_params:
_path = itp_paths.pop()
write_nonbond_params(system, _path, C6C12)
include_string += f'\n #include "{_path}"\n'
Copy link
Member

Choose a reason for hiding this comment

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

I guess we need the itp_paths because of the multichain Go thing? Or could we generate sensible names by doing _path = f"{system.molecules[0].meta['moltype']}_atomtypes.itp" or something along those lines?

Copy link
Member

@pckroon pckroon Dec 6, 2023

Choose a reason for hiding this comment

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

Did we ever reach a conclusion on this? My original comment mentioned generating the _path s based on moltypes. IIRC the outcome was that we can't do that since things like nbparams are system-wide attributes.

Copy link
Member Author

Choose a reason for hiding this comment

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

shall we make it a defaultdict instead? That is each nonbonded section gets a default file name assigned as dict? Perhaps more clear than a list

Copy link
Member

Choose a reason for hiding this comment

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

I think that would be a great improvement

# Write the ITP files for the molecule types, and prepare writing the
# [ molecules ] section of the top file.
# * We write one ITP file for each different moltype in the system, the
Expand Down Expand Up @@ -166,11 +180,11 @@
header[-1] = header[-1] + "\n"
header.append("Pleas cite the following papers:")
for citation in molecule.citations:
cite_string = citation_formatter(

Check warning on line 183 in vermouth/gmx/topology.py

View check run for this annotation

Codecov / codecov/patch

vermouth/gmx/topology.py#L183

Added line #L183 was not covered by tests
molecule.force_field.citations[citation]
)
LOGGER.info("Please cite: " + cite_string)
header.append(cite_string)

Check warning on line 187 in vermouth/gmx/topology.py

View check run for this annotation

Codecov / codecov/patch

vermouth/gmx/topology.py#L186-L187

Added lines #L186 - L187 were not covered by tests
vermouth.gmx.itp.write_molecule_itp(molecule, outfile, header=header)
this_moltype_len = len(molecule.meta["moltype"])
if this_moltype_len > max_name_length:
Expand Down
10 changes: 2 additions & 8 deletions vermouth/processors/water_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@

from .processor import Processor
from ..graph_utils import make_residue_graph
from ..rcsu.go_utils import get_go_type_from_attributes, _get_bead_size
from ..rcsu.go_utils import get_go_type_from_attributes, _get_bead_size, _in_resid_region
from ..gmx.topology import NonbondParam

def _in_region(resid, regions):
for start, stop in regions:
if start <= resid <= stop:
return True
return False

class ComputeWaterBias(Processor):
"""
Processor which computes the water bias for
Expand Down Expand Up @@ -91,13 +85,13 @@
chain = res_graph.nodes[res_node]['chain']
resname = res_graph.nodes[res_node]['resname']

if _in_region(resid, self.idr_regions):
if _in_resid_region(resid, self.idr_regions):
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
eps = self.water_bias.get('idr', 0.0)
elif self.auto_bias:
sec_struc = res_graph.nodes[res_node]['cgsecstruct']
eps = self.water_bias.get(sec_struc, 0.0)
else:
continue

Check warning on line 94 in vermouth/processors/water_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/processors/water_bias.py#L94

Added line #L94 was not covered by tests

if eps == 0.0:
continue
Expand Down Expand Up @@ -126,13 +120,13 @@
Assign water bias for a single molecule
"""
if not self.system:
raise IOError('This processor requires a system.')

Check warning on line 123 in vermouth/processors/water_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/processors/water_bias.py#L123

Added line #L123 was not covered by tests

if not molecule.meta.get('moltype'):
raise ValueError('The molecule does not have a moltype name.')

Check warning on line 126 in vermouth/processors/water_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/processors/water_bias.py#L126

Added line #L126 was not covered by tests

if hasattr(molecule, 'res_graph'):
res_graph = molecule.res_graph

Check warning on line 129 in vermouth/processors/water_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/processors/water_bias.py#L129

Added line #L129 was not covered by tests
else:
res_graph = make_residue_graph(molecule)

Expand Down
3 changes: 2 additions & 1 deletion vermouth/rcsu/contact_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def read_go_map(file_path):
continue

if tokens[0] == "R" and len(tokens) == 18:
contacts.append((int(tokens[1]), tokens[2], int(tokens[4]), tokens[5]))
contacts.append((int(tokens[5]), tokens[4], int(tokens[9]), tokens[8]))

if len(contacts) == 0:
raise IOError("You contact map is empty. Are you sure it has the right formatting?")

return contacts
26 changes: 11 additions & 15 deletions vermouth/rcsu/go_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,31 @@
"""
Wrapping all processors for the go model.
"""
def __init__(self, processor_list, **kwargs):
def __init__(self, processor_list):
self.processor_list = processor_list
self.kwargs = kwargs
self.kwargs = {}

def prepare_run(self, system):
def prepare_run(self, system, moltype):
"""
Things to do before running the pipeline.
"""
# merge all molecules in the system
# this will eventually become deprecated
# with the proper Go-model for multimers
vermouth.MergeAllMolecules().run_system(system)
pckroon marked this conversation as resolved.
Show resolved Hide resolved
for molecule in system.molecules:
res_graph = vermouth.graph_utils.make_residue_graph(system.molecules[0])
molecule.residue_graph = res_graph
molecule = system.molecules[0]

Check warning on line 40 in vermouth/rcsu/go_pipeline.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_pipeline.py#L39-L40

Added lines #L39 - L40 were not covered by tests
# res_graph = vermouth.graph_utils.make_residue_graph(molecule)
# molecule.res_graph = res_graph
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
molecule.meta['moltype'] = moltype

Check warning on line 43 in vermouth/rcsu/go_pipeline.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_pipeline.py#L43

Added line #L43 was not covered by tests

def postprocess_run(self, system):
"""
Do required post-processing.
"""
pass

def run_system(self, system):
self.prepare_run(self, system)
def run_system(self, system, **kwargs):
self.kwargs = kwargs
self.prepare_run(system, moltype=kwargs['moltype'])

Check warning on line 47 in vermouth/rcsu/go_pipeline.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_pipeline.py#L46-L47

Added lines #L46 - L47 were not covered by tests
for processor in self.processor_list:
process_args = inspect.getfullargspec(processor).args

Check warning on line 49 in vermouth/rcsu/go_pipeline.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_pipeline.py#L49

Added line #L49 was not covered by tests
process_args_values = {self.kwargs[arg] for arg in process_args}
process_args_values = {arg:self.kwargs[arg] for arg in kwargs.keys() if arg in process_args}
processor(**process_args_values).run_system(system)
return system

Check warning on line 52 in vermouth/rcsu/go_pipeline.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_pipeline.py#L51-L52

Added lines #L51 - L52 were not covered by tests

GoPipeline = GoProcessorPipline([SetMoleculeMeta,
VirtualSideCreator,
Expand Down
78 changes: 47 additions & 31 deletions vermouth/rcsu/go_structure_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"""
import numpy as np
import networkx as nx
from ..graph_utils import make_residue_graph
from ..molecule import Interaction
from ..processors.processor import Processor
from ..selectors import filter_minimal, select_backbone
from ..gmx.topology import NonbondParam
from .go_utils import get_go_type_from_attributes

class ComputeStructuralGoBias(Processor):
Expand Down Expand Up @@ -48,8 +50,8 @@
cutoff_long,
go_eps,
res_dist,
res_graph=None,
prefix="VS"):
moltype,
res_graph=None):
"""
Initialize the Processor with arguments required
to setup the Go model structural bias.
Expand All @@ -71,21 +73,28 @@
the residue graph they are ignored; this
is similar to sequence distance but takes
into account disulfide bridges for example
moltype: str
name of the molecule to treat
res_graph: :class:vermouth.Molecule
residue graph of the molecule; if None it
get's generated automatically
prefix: str
prefix for all virtual-site atomtypes
system: :class:vermouth.System
the system
magic_number: float
magic number for Go contacts from the old
GoVirt script.
"""
self.contact_map = contact_map
self.cutoff_short = cutoff_short
self.cutoff_long = cutoff_long
self.go_eps = go_eps
self.res_dist = res_dist
self.prefix = prefix
self.res_graph = res_graph
self.moltype = moltype

Check warning on line 92 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L87-L92

Added lines #L87 - L92 were not covered by tests
# don't modify
self.res_graph = None
self.system = None
self.__chain_id_to_resnode = {}
self.magic_number = 1.12246204830

Check warning on line 97 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L94-L97

Added lines #L94 - L97 were not covered by tests
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved

# do not overwrite when subclassing
def _chain_id_to_resnode(self, chain, resid):
pckroon marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -107,20 +116,20 @@
a dict matching the chain,resid to the self.res_graph node
"""
if self.__chain_id_to_resnode:
return self.__chain_id_to_resnode
return self.__chain_id_to_resnode[(chain, resid)]

Check warning on line 119 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L119

Added line #L119 was not covered by tests

# for each residue collect the chain and residue in a dict
# we use this later for identifying the residues from the
# contact map
for resnode in self.res_graph.nodes:
chain = self.res_graph.nodes[resnode].get('chain', None)

Check warning on line 125 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L125

Added line #L125 was not covered by tests
# in vermouth within a molecule all resid are unique
# when merging multiple chains we store the old resid
# the go model always references the input resid i.e.
# the _old_resid
resid = self.res_graph.nodes[resnode].get('_old_resid')
self.__chain_id_to_resnode[(chain, resid)] = resnode
return self.__chain_id_to_resnode
return self.__chain_id_to_resnode[(chain, resid)]

Check warning on line 132 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L130-L132

Added lines #L130 - L132 were not covered by tests

def contact_selector(self, molecule):
"""
Expand All @@ -140,47 +149,47 @@
list of node keys and distance
"""
# distance_matrix of elegible pairs as tuple(node, node, dist)
contact_matrix = []

Check warning on line 152 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L152

Added line #L152 was not covered by tests
# find all pairs of residues that are within bonded distance of
# self.res_dist
connected_pairs = dict(nx.all_pairs_shortest_path_length(self.res_graph,

Check warning on line 155 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L155

Added line #L155 was not covered by tests
cutoff=self.res_dist))
for contact in self.contact_map:
resIDA, chainA, resIDB, chainB = contact

Check warning on line 158 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L158

Added line #L158 was not covered by tests
# identify the contact in the residue graph based on
# chain ID and resid
resA = self.chain_id_to_resnode[(chainA, resIDA)]
resB = self.chain_id_to_resnode[(chainB, resIDB)]
resA = self._chain_id_to_resnode(chainA, resIDA)
resB = self._chain_id_to_resnode(chainB, resIDB)

Check warning on line 162 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L161-L162

Added lines #L161 - L162 were not covered by tests
# make sure that both residues are not connected
# note: contacts should be symmteric so we only
# check against one
if resB not in connected_pairs[resA]:
# now we lookup the backbone nodes within the residue contact
bb_node_A = next(filter_minimal(self.res_graph.nodes[resB], select_backbone))
bb_node_B = next(filter_minimal(self.res_graph.nodes[resB], select_backbone))
bb_node_A = next(filter_minimal(self.res_graph.nodes[resA]['graph'], select_backbone))
bb_node_B = next(filter_minimal(self.res_graph.nodes[resB]['graph'], select_backbone))

Check warning on line 169 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L168-L169

Added lines #L168 - L169 were not covered by tests
# compute the distance between bb-beads
dist = np.linalg.norm(molecule.nodes[bb_node_A]['position'] -

Check warning on line 171 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L171

Added line #L171 was not covered by tests
molecule.nodes[bb_node_B]['position'])
# verify that the distance between BB-beads satisfies the
# cut-off criteria
if self.cut_off_large > dist > self.cutoff_short:
if self.cutoff_long > dist > self.cutoff_short:
# find the go virtual-sites for this residue
# probably can be done smarter but mehhhh
atype_a = get_go_type_from_attributes(molecule,
resid=resIDA,
chain=chainA,
prefix=self.prefix)
atype_b = get_go_type_from_attributes(molecule,
resid=resIDB,
chain=chainB,
prefix=self.prefix)
atype_a = next(get_go_type_from_attributes(self.res_graph.nodes[resA]['graph'],

Check warning on line 178 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L178

Added line #L178 was not covered by tests
resid=resIDA,
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
chain=chainA,
prefix=self.moltype))
atype_b = next(get_go_type_from_attributes(self.res_graph.nodes[resB]['graph'],

Check warning on line 182 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L182

Added line #L182 was not covered by tests
resid=resIDB,
chain=chainB,
prefix=self.moltype))
# generate backbone backbone exclusions
# perhaps one day can be it's own function
excl = Interaction(atoms=(bb_node_A, bb_node_B), parameters=[], meta={"group": "Go model exclusion"})
molecule.interactions['exclusions'].append(excl)

Check warning on line 189 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L188-L189

Added lines #L188 - L189 were not covered by tests

contact_matrix.append((atype_a, atype_b, dist))
return contact_matrix

Check warning on line 192 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L191-L192

Added lines #L191 - L192 were not covered by tests

def compute_go_interaction(self, contacts):
"""
Expand All @@ -198,15 +207,27 @@
dict[frozenset(str, str): float]
dict of interaction parameters indexed by atomtype
"""
go_inters = {}

Check warning on line 210 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L210

Added line #L210 was not covered by tests
for atype_a, atype_b, dist in contacts:
# compute the LJ sigma paramter for this contact
# 1.12246204830 is a magic number by Sebastian
sigma = dist / 1.12246204830
sigma = dist / self.magic_number

Check warning on line 214 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L214

Added line #L214 was not covered by tests
# find the go virtual-sites for this residue
# probably can be done smarter but mehhhh
go_inters[frozenset(atype_a, atype_b)] = (sigma, self.go_eps)
return go_inters
contact_bias = NonbondParam(atoms=(atype_a, atype_b),

Check warning on line 217 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L217

Added line #L217 was not covered by tests
sigma=sigma,
epsilon=self.go_eps,
meta={"comment": ["go bond {resid_a} {resid_b}"]})
self.system.gmx_topology_params["nonbond_params"].append(contact_bias)

Check warning on line 221 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L221

Added line #L221 was not covered by tests

def run_molecule(self, molecule):
self.res_graph = make_residue_graph(molecule)

Check warning on line 224 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L224

Added line #L224 was not covered by tests
# compute the contacts; this also creates
# the exclusions
contacts = self.contact_selector(molecule)

Check warning on line 227 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L227

Added line #L227 was not covered by tests
# compute the interaction parameters
self.compute_go_interaction(contacts)
return molecule

Check warning on line 230 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L229-L230

Added lines #L229 - L230 were not covered by tests

def run_system(self, system):
"""
Expand All @@ -217,11 +238,6 @@
system: vermouth.system.System
The system to process. Is modified in-place.
"""
self.system = system

Check warning on line 241 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L241

Added line #L241 was not covered by tests
for molecule in system.molecules:
# compute the contacts; this also creates
# the exclusions
contacts = self.contact_selector(molecule)
# compute the interaction parameters
inters = self.compute_go_interaction(contacts)
# update the contacts for the system
self.system.gmx_topology_params.upadte(inters)
self.run_molecule(molecule)

Check warning on line 243 in vermouth/rcsu/go_structure_bias.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_structure_bias.py#L243

Added line #L243 was not covered by tests
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions vermouth/rcsu/go_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@
attrs = molecule.nodes[node]
if attributes_match(attrs, kwargs) and attrs['atype'].startswith(prefix):
yield attrs['atype']

resid = kwargs['resid']
chain = kwargs['chain']
raise IOError(f"Could not find GoVs with resid {resid} in chain {chain}.")

Check warning on line 49 in vermouth/rcsu/go_utils.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_utils.py#L47-L49

Added lines #L47 - L49 were not covered by tests
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved

def _in_resid_region(resid, regions):
"""
Expand All @@ -64,7 +63,9 @@
-------
bool
"""
for low, up in regions:
for limits in regions:
# perhaps someone gives them as reversed
low, up = sorted(limits)
if low <= resid <= up:
return True
return False
Expand Down
2 changes: 1 addition & 1 deletion vermouth/rcsu/go_vs_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@
Assign molecule type names to the molecules in a system.
:func:`add_virtual_sites`
"""
def __init__(self, sections=('exclusions', )):
def __init__(self, sections=()):
self.sections = sections
self.system = None

def run_molecule(self, molecule):
moltype = molecule.meta.get('moltype')
if not moltype:
raise ValueError('The molecule does not have a moltype name.')

Check warning on line 55 in vermouth/rcsu/go_vs_includes.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_vs_includes.py#L55

Added line #L55 was not covered by tests

if not self.system:
raise IOError('This processor requires a system.')

Check warning on line 58 in vermouth/rcsu/go_vs_includes.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_vs_includes.py#L58

Added line #L58 was not covered by tests

self.add_virtual_sites(molecule, prefix=moltype)

includes = molecule.meta.get('post_section_lines', {})
for section in self.sections:
section_includes = includes.get(section, [])
section_includes.append('#include "{moltype}_{section}_VirtGoSites.itp"'

Check warning on line 65 in vermouth/rcsu/go_vs_includes.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_vs_includes.py#L64-L65

Added lines #L64 - L65 were not covered by tests
.format(moltype=moltype, section=section))
includes[section] = section_includes

Check warning on line 67 in vermouth/rcsu/go_vs_includes.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_vs_includes.py#L67

Added line #L67 was not covered by tests
molecule.meta['post_section_lines'] = includes
return molecule

Expand Down Expand Up @@ -106,7 +106,7 @@
# If there are no atoms, then there is nothing to do. We can exit early,
# avoiding to deal with empty iterators.
if not molecule.nodes:
return

Check warning on line 109 in vermouth/rcsu/go_vs_includes.py

View check run for this annotation

Codecov / codecov/patch

vermouth/rcsu/go_vs_includes.py#L109

Added line #L109 was not covered by tests
virtual_site_nodes = []
virtual_sites = []
atomtypes = {}
Expand Down
6 changes: 5 additions & 1 deletion vermouth/tests/gmx/test_itp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def dummy_molecule():
'charge_group': 1, 'charge': 0, 'mass': 72
}),
(1, {
'atype': 'A', 'resid': 1, 'resname': 'X', 'atomname': 'A',
'atype': 'B', 'resid': 1, 'resname': 'X', 'atomname': 'B',
'charge_group': 1, 'charge': 0, 'mass': 72
}),
(2, {
'atype': 'C', 'resid': 1, 'resname': 'X', 'atomname': 'C',
'charge_group': 1, 'charge': 0, 'mass': 72
}),
))
Expand Down
Loading
Loading