How to use the moltemplate.ttree.Render function in moltemplate

To help you get started, we’ve selected a few moltemplate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jewettaij / moltemplate / moltemplate / lttree.py View on Github external
# First: To edit the content of a template,
            #        you need to make a deep local copy of it
            tmpl_list = []
            for entry in command.tmpl_list:
                if isinstance(entry, TextBlock):
                    tmpl_list.append(TextBlock(entry.text,
                                               entry.srcloc))  # , entry.srcloc_end))
                else:
                    tmpl_list.append(entry)

            #     Now throw away lines with deleted variables

            DeleteLinesWithBadVars(tmpl_list)

            # --- Now render the text ---
            text = Render(tmpl_list,
                          substitute_vars)

            # ---- Coordinates of the atoms, must be rotated
            # and translated after rendering.
            # In addition, other vectors (dipoles, ellipsoid orientations)
            # must be processed.
            # This requires us to re-parse the contents of this text
            # (after it has been rendered), and apply these transformations
            # before passing them on to the caller.
            if command.filename == data_atoms:
                text = TransformAtomText(text, matrix_stack.M, settings)
            elif command.filename == data_ellipsoids:
                text = TransformEllipsoidText(text, matrix_stack.M, settings)
            if command.filename == data_masses:
                text = AddAtomTypeComments(tmpl_list,
                                           substitute_vars,
github jewettaij / moltemplate / moltemplate / ettree.py View on Github external
#        you need to make a deep local copy of it
            tmpl_list = []
            for entry in command.tmpl_list:
                if isinstance(entry, TextBlock):
                    tmpl_list.append(TextBlock(entry.text, 
                                               entry.srcloc)) #, entry.srcloc_end))
                else:
                    tmpl_list.append(entry)


            # --- Now throw away lines with deleted variables ---

            DeleteLinesWithBadVars(tmpl_list)

            # --- Now render the text ---
            text = Render(tmpl_list, 
                          substitute_vars)

            # ---- Coordinates of the atoms, must be rotated 
            # and translated after rendering.
            # In addition, other vectors (dipoles, ellipsoid orientations)
            # must be processed.
            # This requires us to re-parse the contents of this text
            # (after it has been rendered), and apply these transformations
            # before passing them on to the caller.
            if command.filename == data_atoms:
                text = TransformAtomText(text, matrix_stack.M)

            files_content[command.filename].append(text)


        elif isinstance(command, ScopeBegin):
github jewettaij / moltemplate / moltemplate / lttree.py View on Github external
# Now flatten the "table" (which is a list-of-lists) 
    # into a simple 1-dimensional list
    # (of alternating VarRefs and TextBlocks, in this case)

    templ_list = [entry for sublist in table for entry in sublist]

    # Note: This is equivalent to
    # templ_list = []
    # for sublist in table:
    #     for entry in sublist:
    #         templ_list.append(entry)
    # When building list comprehensions with multiple "for" tokens,
    # the outer loop comes first (ie "for sublist in table")

    # Now render this text and return it to the caller:
    return Render(templ_list, substitute_vars)