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

Comments #460

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 38 additions & 2 deletions vermouth/gmx/itp_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import collections
from vermouth.molecule import (Block, Interaction)
from vermouth.parser_utils import (SectionLineParser, _tokenize)
from vermouth.parser_utils import split_comments

class ITPDirector(SectionLineParser):
"""
Expand Down Expand Up @@ -58,6 +59,39 @@ def __init__(self, force_field):
}
# a list of nodes of current-block
self.current_atom_names = []
self.current_comment = None

def parse(self, file_handle):
"""
Reads lines from `file_handle`, and calls :meth:`dispatch` to find
which method to call to do the actual parsing. Yields the result of
that call, if it's not `None`.
At the end, calls :meth:`finalize`, and yields its results, iff
it's not None.
Parameters
----------
file_handle: collections.abc.Iterable[str]
The data to parse. Should produce lines of data.
Yields
------
object
The results of dispatching to parsing methods, and of
:meth:`finalize`.
"""
lineno = 0
for lineno, line in enumerate(file_handle, 1):
line, comment = split_comments(line, self.COMMENT_CHAR)
self.current_comment = comment
if not line:
continue
result = self.dispatch(line)(line, lineno)

if result is not None:
yield result

result = self.finalize(lineno)
if result is not None:
yield result

def dispatch(self, line):
"""
Expand Down Expand Up @@ -383,7 +417,6 @@ def _base_parser(self, tokens, context, section, atom_idxs):
"""
Converts an interaction line into a vermouth interaction
tuple. It updates the block interactions in place.

Parameters
----------
tokens: collections.deque[str]
Expand All @@ -404,7 +437,10 @@ def _base_parser(self, tokens, context, section, atom_idxs):
if self.current_meta:
meta = {self.current_meta['condition']: self.current_meta['tag']}
else:
meta = {} #dict(collections.ChainMap(meta, apply_to_all_interactions))
meta = {}

if self.current_comment:
meta['comment'] = self.current_comment

interaction = Interaction(
atoms=treated_atoms,
Expand Down
2 changes: 1 addition & 1 deletion vermouth/processors/apply_rubber_band.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def apply_rubber_band(molecule, selector,
type_='bonds',
atoms=(from_key, to_key),
parameters=[bond_type, length, force_constant],
meta={'group': 'Rubber band'},
meta={'group': 'Rubber band', 'comment': 'elastic-bond'},
)


Expand Down