Пример #1
0
 def _redirector(self, file_name, ast_node, caller):
     body = caller()
     file_name = os.path.join(self.environment.globals['output_dir'], file_name)
     mkdirs.mkdirs(file_name, exists_ok=True)
     with open(file_name, 'w') as f:
         f.write(body)
     return ''
Пример #2
0
    def _save_compound(self, compound, system_name, forcefield, ast_node, caller):

        import mbuild as mb
        if isinstance(compound, mb.Compound):
            system_name = os.path.join(self.environment.globals['output_dir'], system_name)
            mkdirs.mkdirs(system_name, exists_ok=True)
            compound.save(system_name, forcefield=forcefield, overwrite=True)
        else:
            if isinstance(compound, string_types) and re.match(r'^\s*\{\{\s*\w+\s*\}\}\s*$', compound, 0):
                raise TemplateSyntaxError("Context is not an mBuild Compound, but '{}'".format(compound), lineno=0)
            else:
                raise TemplateSyntaxError("Context is not an mBuild Compound, but of type {}".format(type(compound)), lineno=0)

        return ''