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 84 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
225 changes: 111 additions & 114 deletions bin/martinize2
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ from vermouth.map_input import (
generate_all_self_mappings,
combine_mappings,
)
from vermouth.rcsu.contact_map import read_go_map
from vermouth.rcsu.go_pipeline import GoPipeline
from vermouth.citation_parser import citation_formatter
from vermouth.gmx.topology import write_gmx_topology

# TODO Since vermouth's __init__.py does some logging (KDTree), this may or may
# not work as intended. Investigation required.
Expand Down Expand Up @@ -188,96 +191,6 @@ def martinize(system, mappings, to_ff, delete_unknown=False):
vermouth.LocateChargeDummies().run_system(system)
return system


def write_gmx_topology(system, top_path, defines=(), header=()):
"""
Writes a Gromacs .top file for the specified system.
"""
if not system.molecules:
raise ValueError("No molecule in the system. Nothing to write.")

# 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
# moltype being defined by the name provided under the "moltype" meta of
# the molecules. If more than one molecule share the same moltype, we use
# the first one to write the ITP file.
moltype_written = set()
# * We keep track of the length of the longer moltype name, to align the
# [ molecules ] section.
max_name_length = 0
# * We keep track of groups of successive molecules with the same moltypes.
moltype_count = [] # items will be [moltype, number of molecules]

# Iterate over groups of successive molecules with the same moltypes. We
# shall *NOT* sort the molecules before hand, as groups of successive
# molecules with the same moltype can be interupted by other moltypes, and
# we want to reflect these interuptions in the [ molecules ] section of the
# top file.
molecule_groups = itertools.groupby(
system.molecules, key=lambda x: x.meta["moltype"]
)
for moltype, molecules in molecule_groups:
molecule = next(molecules)
if moltype not in moltype_written:
# A given moltype can appear more than once in the sequence of
# molecules, without being uninterupted by other moltypes. Even in
# that case, we want to write the ITP only once.
with deferred_open("{}.itp".format(moltype), "w") as outfile:
# here we format and merge all citations
header[-1] = header[-1] + "\n"
header.append("Pleas cite the following papers:")
for citation in molecule.citations:
cite_string = citation_formatter(
molecule.force_field.citations[citation]
)
LOGGER.info("Please cite: " + cite_string)
header.append(cite_string)
vermouth.gmx.itp.write_molecule_itp(molecule, outfile, header=header)
this_moltype_len = len(molecule.meta["moltype"])
if this_moltype_len > max_name_length:
max_name_length = this_moltype_len
moltype_written.add(moltype)
# We already removed one element from the "molecules" generator, do not
# forget to count it in the number of molecules in that group.
moltype_count.append([moltype, 1 + len(list(molecules))])

# Write the top file
template = textwrap.dedent(
"""\
{defines}
#include "martini.itp"
{includes}

[ system ]
Title of the system

[ molecules ]
{molecules}
"""
)
include_string = "\n".join(
'#include "{}.itp"'.format(molecule_type) for molecule_type, _ in moltype_count
)
molecule_string = "\n".join(
"{mtype:<{length}} {num}".format(
mtype=mtype, num=num, length=max_name_length
)
for mtype, num in moltype_count
)
define_string = "\n".join("#define {}".format(define) for define in defines)
with deferred_open(str(top_path), "w") as outfile:
outfile.write(
textwrap.dedent(
template.format(
includes=include_string,
molecules=molecule_string,
defines=define_string,
)
)
)


def _cys_argument(value):
"""
Convert and validate the value of the cys option for argparse.
Expand Down Expand Up @@ -618,16 +531,82 @@ def entry():
)
go_group = parser.add_argument_group("Virtual site based GoMartini")
go_group.add_argument(
"-govs-includes",
action="store_true",
default=False,
help="Write include statements to use Vitrual Site Go Martini.",
"-go",
dest="go",
required=False,
type=Path,
default=None,
help="Contact map to be used for the Martini Go model."
"Currently, only one format is supported. See docs.",
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
)
go_group.add_argument(
"-go-eps",
dest="go_eps",
type=float,
default=9.414,
help=("The strength of the Go model structural bias in kJ/mol."),
)
go_group.add_argument(
"-govs-moltype",
"-go-moltype",
dest="govs_moltype",
default="molecule_0",
help=("Set the name of the molecule when using " "Virtual Sites GoMartini."),
)
go_group.add_argument(
"-go-low",
dest="go_low",
type=float,
default=0.3,
help=("Minimum distance (nm) below which contacts are removed."),
)
go_group.add_argument(
"-go-up",
dest="go_up",
type=float,
default=1.1,
help=("Maximum distance (nm) above which contacts are removed."),
)
go_group.add_argument(
"-go-res-dist",
dest="go_res_dist",
type=int,
default=3,
help=("Minimum graph distance (similar seqeuence distance) below which"
pckroon marked this conversation as resolved.
Show resolved Hide resolved
"contacts are removed. "),
)

water_group = parser.add_argument_group("Apply water bias.")
water_group.add_argument(
"-water-bias",
dest="water_bias",
action="store_true",
default=False,
help=("Automatically apply water bias to different secondary structure elements."),
)
water_group.add_argument(
"-water-bias-eps",
dest="water_bias_eps",
nargs='+',
type=lambda s: s.split(":"),
default=[],
help=("Define the strength of the water bias by secondary structure type. "
"For example, use H:3.6, C:2.1 to bias helixes and coils. "
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
"Using the idr option (e.g. idr:2.1) intrinsically disordered regions "
"are biased seperately."),
)
water_group.add_argument(
"-id-regions",
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
dest="water_idrs",
type=lambda s: s.split(":"),
default=[],
nargs='+',
help=("Intrinsically disordered regions specified by resid."
"These parts are biased differently when applying a water bias."
"format: <start_resid_1>:<end_resid_1> <start_resid_2>:<end_resid_2>..."
),
)


prot_group = parser.add_argument_group("Protein description")
prot_group.add_argument(
"-scfix",
Expand Down Expand Up @@ -815,7 +794,7 @@ def entry():
print(", ".join(sorted(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 @@ -963,24 +942,24 @@ def entry():
node_selector = node_selectors[args.posres]
vermouth.ApplyPosres(node_selector, args.posres_fc).run_system(system)

if args.govs_includes:
# The way Virtual Site GoMartini works has to be in sync with
# Sebastian's create_goVirt.py script, until the method is fully
# implemented in vermouth. One call of martinize2 must create a single
# molecule, regardless of the number of fragments in the input.
# The molecule type name is provided as an input with the -govs-moltype
# flag to be consistent with the name provided to Sebastian's script.
# The name cannot be guessed because a system may need to be composed
# from multiple calls to martinize2 and create_goVirt.py.
LOGGER.info("Adding includes for Virtual Site Go Martini.", type="step")
LOGGER.info(
"The output topology will require files generated by " '"create_goVirt.py".'
)
vermouth.MergeAllMolecules().run_system(system)
vermouth.SetMoleculeMeta(moltype=args.govs_moltype).run_system(system)
vermouth.GoVirtIncludes().run_system(system)
# Generate the Go model if required
if args.go:
LOGGER.info("Reading Go model contact map.", type="step")
go_map = read_go_map(args.go)
LOGGER.info("Generating the Go model.", type="step")
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"]
else:
# don't write non-bonded interactions
itp_paths = []
# Merge chains if required.
if args.merge_chains:
for chain_set in args.merge_chains:
Expand Down Expand Up @@ -1039,6 +1018,19 @@ def entry():
)
rubber_band_processor.run_system(system)

# If required add some water bias
if args.water_bias:
# if the go model hasn't been used we need to create virtual
# sites for the biasing
if not args.go:
vermouth.rcsu.go_vs_includes.VirtualSiteCreator().run_system(system)
itp_paths = ["virtual_sites_atomtypes.itp", "virtual_sites_nonbond_params.itp"]
# now we add a bias by defining specific virtual-site water interactions
vermouth.processors.ComputeWaterBias(args.water_bias,
{ s:float(eps) for s, eps in args.water_bias_eps},
[(int(start), int(stop)) for start, stop in args.water_idrs],
).run_system(system)

# Here we need to add the resids from the PDB back if that is needed
if args.resid_handling == "input":
for molecule in system.molecules:
Expand All @@ -1048,7 +1040,7 @@ def entry():
# The Martini Go model assumes that we do not mess with the order of
# particles in any way especially the virtual sites needed for the Go
# model, thus we skip the sorting here altogether.
if not args.govs_includes:
if not args.go:
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.info("Sorting atomids", type="step")
vermouth.SortMoleculeAtoms().run_system(system)

Expand Down Expand Up @@ -1083,7 +1075,12 @@ def entry():
]

if args.top_path is not None:
write_gmx_topology(system, args.top_path, defines=defines, header=header)
write_gmx_topology(system,
args.top_path,
itp_paths=itp_paths,
C6C12=False,
defines=defines,
header=header)

# Write a PDB file.
vermouth.pdb.write_pdb(system, str(args.outpath), omit_charges=True)
Expand Down
6 changes: 3 additions & 3 deletions doc/source/martinize2_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ There can be any number of post processing steps. For example to add an elastic
network, or to generate Go virtual sites. We will not describe their function
here in detail. Instead, see for example
:class:`~vermouth.processors.apply_rubber_band.ApplyRubberBand` and
:class:`~vermouth.processors.go_vs_includes.GoVirtIncludes`.
:class:`~vermouth.rcsu.go_vs_includes.VirtualSiteCreator`.

Relevant CLI options: ``-elastic``, ``-ef``, ``-el``, ``-eu``, ``-ermd``,
``-ea``, ``-ep``, ``-em``, ``-eb``, ``-eunit``, ``-govs-include``,
``-govs-moltype``
``-ea``, ``-ep``, ``-em``, ``-eb``, ``-eunit``, ``-go``,
``-go-eps``, ``-go-moltype``, ``-go-low``, ``-go-up``, ``-go-res-dist``

6) Write output
===============
Expand Down
4 changes: 4 additions & 0 deletions vermouth/data/force_fields/martini3001/general.ff
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@

[ variables ]
center_weight "mass"
regular "0.47"
small "0.41"
tiny "0.34"
water_type "W"
Loading