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

[2] Coord gen new #29

Merged
merged 27 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
07cfacd
structure generator
fgrunewald Apr 28, 2020
54a9ee2
update exec
fgrunewald May 20, 2020
e3c0f17
fix ordering
fgrunewald May 20, 2020
56916fb
merge master
fgrunewald May 20, 2020
7ba17f4
implement gen-pairs, set default nb to LJ sig-eps, some comments
fgrunewald May 24, 2020
bc29b5f
address comments
fgrunewald May 24, 2020
3698ac9
restart minimizer upon failed optimization
fgrunewald May 24, 2020
b568b49
adding doc-string for all structure related functions
fgrunewald May 30, 2020
19a98d4
merge master
fgrunewald May 30, 2020
799c343
replace combination rule in random-walk with the one in topology
fgrunewald May 30, 2020
495b830
move replace_defines to topology parser
fgrunewald May 30, 2020
f99455d
implements GROMACS VS
fgrunewald May 31, 2020
23fd3ad
small bug fixes; P3HT lysoPEG PMMA work
fgrunewald May 31, 2020
04c85f1
add license
fgrunewald May 31, 2020
1052bf5
add license and fix order issue in backmap
fgrunewald Jun 1, 2020
909f1fb
fix backmap and tests
fgrunewald Jun 1, 2020
25f1141
last comments
fgrunewald Jun 1, 2020
5e0a960
fix counting of atoms in backmapping
fgrunewald Jun 1, 2020
a4fb1cc
raise Error if molecule or residue is disconnected
fgrunewald Jun 1, 2020
68c5d63
test multiple defines in single interaction
fgrunewald Jun 4, 2020
dffd80e
reanming to snake-case; comments on unitsphere
fgrunewald Jun 4, 2020
3b828aa
introduce explicit preprocess function to topology; raise IOError whe…
fgrunewald Jun 5, 2020
dab0d35
use np.average in vs builder
fgrunewald Jun 5, 2020
ea10348
some linting
fgrunewald Jun 5, 2020
c540e3c
address some comments
fgrunewald Jun 8, 2020
f1a2d40
remove links form replace defines
fgrunewald Jun 8, 2020
4344910
make backmapping and extract_block dependent on atom-name instead of …
fgrunewald Jun 8, 2020
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
61 changes: 61 additions & 0 deletions polyply/src/backmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2020 University of Groningen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .processor import Processor
from .generate_templates import find_atoms
"""
Processor implementing a template based back
mapping to lower resolution coordinates for
a meta molecule.
"""

class Backmap(Processor):
"""
This processor takes a a class:`polyply.src.MetaMolecule` and
places coordinates form a higher resolution createing positions
for the lower resolution molecule associated with the MetaMolecule.
"""
@staticmethod
def _place_init_coords(meta_molecule):
"""
For each residue in a class:`polyply.src.MetaMolecule` the
positions of the atoms associated with that residue stored in
attr:`polyply.src.MetaMolecule.molecule` are created from a
template residue located in attr:`polyply.src.MetaMolecule.templates`.

Parameters
----------
meta_molecule: :class:`polyply.src.MetaMolecule`
"""
count = 0
for node in meta_molecule.nodes:
resname = meta_molecule.nodes[node]["resname"]
cg_coord = meta_molecule.nodes[node]["position"]
template = meta_molecule.templates[resname]
resid = node + 1
low_res_atoms = find_atoms(meta_molecule.molecule, "resid", resid)
for atom_low in low_res_atoms:
atomname = meta_molecule.molecule.nodes[atom_low]["atomname"]
vector = template[atomname]
new_coords = cg_coord + vector
if meta_molecule.molecule.nodes[atom_low]["build"]:
meta_molecule.molecule.nodes[atom_low]["position"] = new_coords

def run_molecule(self, meta_molecule):
"""
Apply placing of coordinates to meta_molecule. For more
detail see `self._place_init_coords`.
"""
self._place_init_coords(meta_molecule)
return meta_molecule
43 changes: 41 additions & 2 deletions polyply/src/gen_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""
High level API for the polyply coordinate generator
"""

import networkx as nx
import vermouth.forcefield
from .generate_templates import GenerateTemplates
from .random_walk import RandomWalk
from .backmap import Backmap
from .topology import Topology

def gen_coords(args):
fgrunewald marked this conversation as resolved.
Show resolved Hide resolved
print("template file")
return None
# Read in the topology
topology = Topology.from_gmx_topfile(name=args.name, path=args.toppath)
topology.preprocess()

# check if molecules are all connected
for molecule in topology.molecules:
if not nx.is_connected(molecule):
msg = ('\n Molecule {} consistes of two disconnected parts. '
'Make sure all atoms/particles in a molecule are '
'connected by bonds, constraints or virual-sites')
raise IOError(msg.format(molecule.name))

# read in coordinates if there are any
if args.coordpath:
topology.add_positions_from_file(args.coordpath)
else:
for molecule in topology.molecules:
for node in molecule.molecule.nodes:
molecule.molecule.nodes[node]["build"] = True

# Build polymer structure
GenerateTemplates().run_system(topology)
RandomWalk().run_system(topology)
Backmap().run_system(topology)
#energy_minimize().run_system(topology)

system = topology.convert_to_vermouth_system()
# Write output
vermouth.gmx.gro.write_gro(system, args.outpath, precision=7,
title='polyply structure', box=(10, 10, 10))
Loading