예제 #1
0
    def test_subsubsection(self):
        """Test of the lib.text.sectioning.subsubsection() function."""

        # Write out the subsubsection.
        file = DummyFileObject()
        subsubsection(file=file, text='Test subsubsection')

        # Read the results.
        lines = file.readlines()
        print("Formatted subsubsection lines:  %s" % lines)

        # Check the title.
        real_lines = [
            '\n',
            'Test subsubsection\n',
            '~~~~~~~~~~~~~~~~~~\n',
            '\n',
        ]
        self.assertEqual(len(lines), len(real_lines))
        for i in range(len(lines)):
            self.assertEqual(lines[i], real_lines[i])
예제 #2
0
def create_geometric_rep(format='PDB', file=None, dir=None, compress_type=0, size=30.0, inc=36, force=False):
    """Create a PDB file containing a geometric object representing the frame order dynamics.

    @keyword format:        The format for outputting the geometric representation.  Currently only the 'PDB' format is supported.
    @type format:           str
    @keyword file:          The name of the file of the PDB representation of the frame order dynamics to create.
    @type file:             str
    @keyword dir:           The name of the directory to place the PDB file into.
    @type dir:              str
    @keyword compress_type: The compression type.  The integer values correspond to the compression type: 0, no compression; 1, Bzip2 compression; 2, Gzip compression.
    @type compress_type:    int
    @keyword size:          The size of the geometric object in Angstroms.
    @type size:             float
    @keyword inc:           The number of increments for the filling of the cone objects.
    @type inc:              int
    @keyword force:         Flag which if set to True will cause any pre-existing file to be overwritten.
    @type force:            bool
    """

    # Printout.
    subsection(file=sys.stdout, text="Creating a PDB file containing a geometric object representing the frame order dynamics.")

    # Checks.
    check_parameters(escalate=2)

    # Initialise.
    titles = []
    structures = []
    representation = []
    sims = []
    file_root = []

    # Symmetry for inverted representations?
    sym = True
    if cdp.model in [MODEL_ROTOR, MODEL_FREE_ROTOR, MODEL_DOUBLE_ROTOR]:
        sym = False

    # The standard representation.
    titles.append("Representation A")
    structures.append(Internal())
    if sym:
        representation.append('A')
        file_root.append("%s_A" % file)
    else:
        representation.append(None)
        file_root.append(file)
    sims.append(False)

    # The inverted representation.
    if sym:
        titles.append("Representation A")
        structures.append(Internal())
        representation.append('B')
        file_root.append("%s_B" % file)
        sims.append(False)

    # The standard MC simulation representation.
    if hasattr(cdp, 'sim_number'):
        titles.append("MC simulation representation A")
        structures.append(Internal())
        if sym:
            representation.append('A')
            file_root.append("%s_sim_A" % file)
        else:
            representation.append(None)
            file_root.append("%s_sim" % file)
        sims.append(True)

    # The inverted MC simulation representation.
    if hasattr(cdp, 'sim_number') and sym:
        titles.append("MC simulation representation B")
        structures.append(Internal())
        representation.append('B')
        file_root.append("%s_sim_B" % file)
        sims.append(True)

    # Loop over each structure and add the contents.
    for i in range(len(structures)):
        # Printout.
        subsubsection(file=sys.stdout, text="Creating the %s." % titles[i])

        # Create a model for each Monte Carlo simulation.
        if sims[i]:
            for sim_i in range(cdp.sim_number):
                structures[i].add_model(model=sim_i+1)

        # Add the pivots.
        add_pivots(structure=structures[i], sims=sims[i])

        # Add all rotor objects.
        add_rotors(structure=structures[i], representation=representation[i], size=size, sims=sims[i])

        # Add the axis systems.
        add_axes(structure=structures[i], representation=representation[i], size=size, sims=sims[i])

        # Add the cone objects.
        if cdp.model not in [MODEL_ROTOR, MODEL_FREE_ROTOR, MODEL_DOUBLE_ROTOR]:
            add_cones(structure=structures[i], representation=representation[i], size=size, inc=inc, sims=sims[i])

        # Add atoms for creating titles.
        add_titles(structure=structures[i], representation=representation[i], displacement=size+10, sims=sims[i])

        # Create the PDB file.
        if format == 'PDB':
            pdb_file = open_write_file(file_root[i]+'.pdb', dir, compress_type=compress_type, force=force)
            structures[i].write_pdb(pdb_file)
            pdb_file.close()
예제 #3
0
def create_ave_pos(format='PDB', file=None, dir=None, compress_type=0, model=1, force=False):
    """Create a PDB file of the molecule with the moving domains shifted to the average position.

    @keyword format:        The format for outputting the geometric representation.  Currently only the 'PDB' format is supported.
    @type format:           str
    @keyword file:          The name of the file for the average molecule structure.
    @type file:             str
    @keyword dir:           The name of the directory to place the PDB file into.
    @type dir:              str
    @keyword compress_type: The compression type.  The integer values correspond to the compression type: 0, no compression; 1, Bzip2 compression; 2, Gzip compression.
    @type compress_type:    int
    @keyword model:         Only one model from an analysed ensemble can be used for the PDB representation of the Monte Carlo simulations, as these consists of one model per simulation.
    @type model:            int
    @keyword force:         Flag which if set to True will cause any pre-existing file to be overwritten.
    @type force:            bool
    """

    # Printout.
    subsection(file=sys.stdout, text="Creating a PDB file with the moving domains shifted to the average position.")

    # Checks.
    if not hasattr(cdp, 'structure'):
        warn(RelaxWarning("No structural data is present, cannot create the average position representation."))
        return

    # Initialise.
    titles = []
    sims = []
    file_root = []
    models = []
    structures = []

    # The real average position.
    titles.append("real average position")
    sims.append(False)
    file_root.append(file)
    models.append([None])

    # The positive MC simulation representation.
    if hasattr(cdp, 'sim_number'):
        titles.append("MC simulation representation")
        sims.append(True)
        file_root.append("%s_sim" % file)
        models.append([i+1 for i in range(cdp.sim_number)])

    # Make a copy of the structural object (so as to preserve the original structure).
    structures.append(deepcopy(cdp.structure))
    if hasattr(cdp, 'sim_number'):
        structures.append(deepcopy(cdp.structure))

    # Delete all but the chosen model for the simulations.
    if hasattr(cdp, 'sim_number') and len(structures[-1].structural_data) > 1:
        # Determine the models to delete.
        to_delete = []
        for model_cont in structures[-1].model_loop():
            if model_cont.num != model:
                to_delete.append(model_cont.num)
        to_delete.reverse()

        # Delete them.
        for num in to_delete:
            structures[-1].structural_data.delete_model(model_num=num)

    # Loop over each representation and add the contents.
    for i in range(len(titles)):
        # Printout.
        subsubsection(file=sys.stdout, text="Creating the %s." % titles[i])

        # Loop over each model.
        for j in range(len(models[i])):
            # Create or set the models, if needed.
            if models[i][j] == 1:
                structures[i].set_model(model_new=1)
            elif models[i][j] != None:
                structures[i].add_model(model=models[i][j])

        # Shift to the average position.
        average_position(structure=structures[i], models=models[i], sim=sims[i])

        # Output to PDB format.
        if format == 'PDB':
            pdb_file = open_write_file(file_name=file_root[i]+'.pdb', dir=dir, compress_type=compress_type, force=force)
            structures[i].write_pdb(file=pdb_file)
            pdb_file.close()
예제 #4
0
파일: geometric.py 프로젝트: tlinnet/relax
def create_geometric_rep(format='PDB',
                         file=None,
                         dir=None,
                         compress_type=0,
                         size=30.0,
                         inc=36,
                         force=False):
    """Create a PDB file containing a geometric object representing the frame order dynamics.

    @keyword format:        The format for outputting the geometric representation.  Currently only the 'PDB' format is supported.
    @type format:           str
    @keyword file:          The name of the file of the PDB representation of the frame order dynamics to create.
    @type file:             str
    @keyword dir:           The name of the directory to place the PDB file into.
    @type dir:              str
    @keyword compress_type: The compression type.  The integer values correspond to the compression type: 0, no compression; 1, Bzip2 compression; 2, Gzip compression.
    @type compress_type:    int
    @keyword size:          The size of the geometric object in Angstroms.
    @type size:             float
    @keyword inc:           The number of increments for the filling of the cone objects.
    @type inc:              int
    @keyword force:         Flag which if set to True will cause any pre-existing file to be overwritten.
    @type force:            bool
    """

    # Printout.
    subsection(
        file=sys.stdout,
        text=
        "Creating a PDB file containing a geometric object representing the frame order dynamics."
    )

    # Checks.
    check_parameters(escalate=2)

    # Initialise.
    titles = []
    structures = []
    representation = []
    sims = []
    file_root = []

    # Symmetry for inverted representations?
    sym = True
    if cdp.model in [MODEL_ROTOR, MODEL_FREE_ROTOR, MODEL_DOUBLE_ROTOR]:
        sym = False

    # The standard representation.
    titles.append("Representation A")
    structures.append(Internal())
    if sym:
        representation.append('A')
        file_root.append("%s_A" % file)
    else:
        representation.append(None)
        file_root.append(file)
    sims.append(False)

    # The inverted representation.
    if sym:
        titles.append("Representation A")
        structures.append(Internal())
        representation.append('B')
        file_root.append("%s_B" % file)
        sims.append(False)

    # The standard MC simulation representation.
    if hasattr(cdp, 'sim_number'):
        titles.append("MC simulation representation A")
        structures.append(Internal())
        if sym:
            representation.append('A')
            file_root.append("%s_sim_A" % file)
        else:
            representation.append(None)
            file_root.append("%s_sim" % file)
        sims.append(True)

    # The inverted MC simulation representation.
    if hasattr(cdp, 'sim_number') and sym:
        titles.append("MC simulation representation B")
        structures.append(Internal())
        representation.append('B')
        file_root.append("%s_sim_B" % file)
        sims.append(True)

    # Loop over each structure and add the contents.
    for i in range(len(structures)):
        # Printout.
        subsubsection(file=sys.stdout, text="Creating the %s." % titles[i])

        # Create a model for each Monte Carlo simulation.
        if sims[i]:
            for sim_i in range(cdp.sim_number):
                structures[i].add_model(model=sim_i + 1)

        # Add the pivots.
        add_pivots(structure=structures[i], sims=sims[i])

        # Add all rotor objects.
        add_rotors(structure=structures[i],
                   representation=representation[i],
                   size=size,
                   sims=sims[i])

        # Add the axis systems.
        add_axes(structure=structures[i],
                 representation=representation[i],
                 size=size,
                 sims=sims[i])

        # Add the cone objects.
        if cdp.model not in [
                MODEL_ROTOR, MODEL_FREE_ROTOR, MODEL_DOUBLE_ROTOR
        ]:
            add_cones(structure=structures[i],
                      representation=representation[i],
                      size=size,
                      inc=inc,
                      sims=sims[i])

        # Add atoms for creating titles.
        add_titles(structure=structures[i],
                   representation=representation[i],
                   displacement=size + 10,
                   sims=sims[i])

        # Create the PDB file.
        if format == 'PDB':
            pdb_file = open_write_file(file_root[i] + '.pdb',
                                       dir,
                                       compress_type=compress_type,
                                       force=force)
            structures[i].write_pdb(pdb_file)
            pdb_file.close()
예제 #5
0
파일: geometric.py 프로젝트: tlinnet/relax
def create_ave_pos(format='PDB',
                   file=None,
                   dir=None,
                   compress_type=0,
                   model=1,
                   force=False):
    """Create a PDB file of the molecule with the moving domains shifted to the average position.

    @keyword format:        The format for outputting the geometric representation.  Currently only the 'PDB' format is supported.
    @type format:           str
    @keyword file:          The name of the file for the average molecule structure.
    @type file:             str
    @keyword dir:           The name of the directory to place the PDB file into.
    @type dir:              str
    @keyword compress_type: The compression type.  The integer values correspond to the compression type: 0, no compression; 1, Bzip2 compression; 2, Gzip compression.
    @type compress_type:    int
    @keyword model:         Only one model from an analysed ensemble can be used for the PDB representation of the Monte Carlo simulations, as these consists of one model per simulation.
    @type model:            int
    @keyword force:         Flag which if set to True will cause any pre-existing file to be overwritten.
    @type force:            bool
    """

    # Printout.
    subsection(
        file=sys.stdout,
        text=
        "Creating a PDB file with the moving domains shifted to the average position."
    )

    # Checks.
    if not hasattr(cdp, 'structure'):
        warn(
            RelaxWarning(
                "No structural data is present, cannot create the average position representation."
            ))
        return

    # Initialise.
    titles = []
    sims = []
    file_root = []
    models = []
    structures = []

    # The real average position.
    titles.append("real average position")
    sims.append(False)
    file_root.append(file)
    models.append([None])

    # The positive MC simulation representation.
    if hasattr(cdp, 'sim_number'):
        titles.append("MC simulation representation")
        sims.append(True)
        file_root.append("%s_sim" % file)
        models.append([i + 1 for i in range(cdp.sim_number)])

    # Make a copy of the structural object (so as to preserve the original structure).
    structures.append(deepcopy(cdp.structure))
    if hasattr(cdp, 'sim_number'):
        structures.append(deepcopy(cdp.structure))

    # Delete all but the chosen model for the simulations.
    if hasattr(cdp, 'sim_number') and len(structures[-1].structural_data) > 1:
        # Determine the models to delete.
        to_delete = []
        for model_cont in structures[-1].model_loop():
            if model_cont.num != model:
                to_delete.append(model_cont.num)
        to_delete.reverse()

        # Delete them.
        for num in to_delete:
            structures[-1].structural_data.delete_model(model_num=num)

    # Loop over each representation and add the contents.
    for i in range(len(titles)):
        # Printout.
        subsubsection(file=sys.stdout, text="Creating the %s." % titles[i])

        # Loop over each model.
        for j in range(len(models[i])):
            # Create or set the models, if needed.
            if models[i][j] == 1:
                structures[i].set_model(model_new=1)
            elif models[i][j] != None:
                structures[i].add_model(model=models[i][j])

        # Shift to the average position.
        average_position(structure=structures[i],
                         models=models[i],
                         sim=sims[i])

        # Output to PDB format.
        if format == 'PDB':
            pdb_file = open_write_file(file_name=file_root[i] + '.pdb',
                                       dir=dir,
                                       compress_type=compress_type,
                                       force=force)
            structures[i].write_pdb(file=pdb_file)
            pdb_file.close()