Example #1
0
    def __init__(self, filename=None, **kwargs):
        """Initialize ITP structure.

        :Arguments:
          *filename*
              read from mdp file
          *kwargs*
              ``#define`` *VAR*  variables that are used at the pre-processing
              stage of the itp file, e.g. *POSRES* ``= True`` will activate a
              ``#ifdef POSRES`` section in the itp file.

        .. SeeAlso:: :mod:`~gromacs.fileformats.preprocessor` describes details about the
                     implementation of preprocessing of the itp file, including
                     the (limited) syntax understood by the preprocesser.
        """
        self.defines = kwargs
        kwargs = {}

        super(ITP, self).__init__(**kwargs)

        self.commentchar = ';'
        self.sections = odict()
        self.parsers = {
            'header': Header,
            'dummy': Dummy,
            }

        if not filename is None:
            self._init_filename(filename)
            self.read(filename)
Example #2
0
 def __init__(self, parent, **kwargs):
     self.parent = parent        # parent section
     self.logger = parent.logger
     self.sections = odict()
     self.__data = kwargs.pop("data", [])
     self.comments = kwargs.pop("comments", [])
     self.parsers = {}
Example #3
0
 def __init__(self, *args, **kwargs):
     kwargs['data'] = odict()
     super(Moleculetype, self).__init__(*args, **kwargs)
     self.parsers = {
         'atoms': Atoms,
         'bonds': Bonds,
         'angles': Angles,
         'dihedrals': Dihedrals,
         'pairs': Pairs,
         'dummy': Dummy,
         }
Example #4
0
    def read(self, filename=None):
        """Read and parse index file *filename*."""
        self._init_filename(filename)

        data = odict()
        with open(self.real_filename) as ndx:
            current_section = None
            for line in ndx:
                line = line.strip()
                if len(line) == 0:
                    continue
                m = self.SECTION.match(line)
                if m:
                    current_section = m.group("name")
                    data[current_section] = []  # can fail if name not legal python key
                    continue
                if not current_section is None:
                    data[current_section].extend(map(int, line.split()))

        super(NDX, self).update(odict([(name, self._transform(atomnumbers)) for name, atomnumbers in data.items()]))
Example #5
0
    def read(self, filename=None):
        """Read and parse mdp file *filename*."""
        self._init_filename(filename)

        def BLANK(i):
            return "B%04d" % i
        def COMMENT(i):
            return "C%04d" % i

        data = odict()
        iblank = icomment = 0
        with open(self.real_filename) as mdp:
            for line in mdp:
                line = line.strip()
                if len(line) == 0:
                    iblank += 1
                    data[BLANK(iblank)] = ''
                    continue
                m = self.COMMENT.match(line)
                if m:
                    icomment += 1
                    data[COMMENT(icomment)] = m.group('value')
                    continue
                # parameter
                m = self.PARAMETER.match(line)
                if m:
                    # check for comments after parameter?? -- currently discarded
                    parameter = m.group('parameter')
                    value =  self._transform(m.group('value'))
                    data[parameter] = value
                else:
                    errmsg = '%(filename)r: unknown line in mdp file, %(line)r' % vars()
                    self.logger.error(errmsg)
                    raise ParseError(errmsg)

        super(MDP,self).update(data)