Пример #1
0
def cone_pdb(cone_type=None, scale=1.0, file=None, dir=None, force=False):
    """Create a PDB file containing a geometric object representing the various cone models.

    Currently the only cone types supported are 'diff in cone' and 'diff on cone'.


    @param cone_type:   The type of cone model to represent.
    @type cone_type:    str
    @param scale:       The size of the geometric object is eqaul to the average pivot-CoM
                        vector length multiplied by this scaling factor.
    @type scale:        float
    @param file:        The name of the PDB file to create.
    @type file:         str
    @param dir:         The name of the directory to place the PDB file into.
    @type dir:          str
    @param force:       Flag which if set to True will cause any pre-existing file to be
                        overwritten.
    @type force:        int
    """

    # Test if the cone models have been determined.
    if cone_type == 'diff in cone':
        if not hasattr(cdp, 'S_diff_in_cone'):
            raise RelaxError(
                "The diffusion in a cone model has not yet been determined.")
    elif cone_type == 'diff on cone':
        if not hasattr(cdp, 'S_diff_on_cone'):
            raise RelaxError(
                "The diffusion on a cone model has not yet been determined.")
    else:
        raise RelaxError("The cone type " + repr(cone_type) + " is unknown.")

    # The number of increments for the filling of the cone objects.
    inc = 20

    # The rotation matrix.
    R = zeros((3, 3), float64)
    two_vect_to_R(array([0, 0, 1], float64),
                  cdp.ave_pivot_CoM / norm(cdp.ave_pivot_CoM), R)

    # The isotropic cone object.
    if cone_type == 'diff in cone':
        angle = cdp.theta_diff_in_cone
    elif cone_type == 'diff on cone':
        angle = cdp.theta_diff_on_cone
    cone_obj = Iso_cone(angle)

    # Create the structural object.
    structure = Internal()

    # Add a structure.
    structure.add_molecule(name='cone')

    # Alias the single molecule from the single model.
    mol = structure.structural_data[0].mol[0]

    # Add the pivot point.
    mol.atom_add(pdb_record='HETATM',
                 atom_num=1,
                 atom_name='R',
                 res_name='PIV',
                 res_num=1,
                 pos=cdp.pivot_point,
                 element='C')

    # Generate the average pivot-CoM vectors.
    print("\nGenerating the average pivot-CoM vectors.")
    sim_vectors = None
    if hasattr(cdp, 'ave_pivot_CoM_sim'):
        sim_vectors = cdp.ave_pivot_CoM_sim
    res_num = generate_vector_residues(mol=mol,
                                       vector=cdp.ave_pivot_CoM,
                                       atom_name='Ave',
                                       res_name_vect='AVE',
                                       sim_vectors=sim_vectors,
                                       res_num=2,
                                       origin=cdp.pivot_point,
                                       scale=scale)

    # Generate the cone outer edge.
    print("\nGenerating the cone outer edge.")
    cap_start_atom = mol.atom_num[-1] + 1
    cone_edge(mol=mol,
              cone_obj=cone_obj,
              res_name='CON',
              res_num=3,
              apex=cdp.pivot_point,
              R=R,
              scale=norm(cdp.pivot_CoM),
              inc=inc)

    # Generate the cone cap, and stitch it to the cone edge.
    if cone_type == 'diff in cone':
        print("\nGenerating the cone cap.")
        cone_start_atom = mol.atom_num[-1] + 1
        generate_vector_dist(mol=mol,
                             res_name='CON',
                             res_num=3,
                             centre=cdp.pivot_point,
                             R=R,
                             phi_max_fn=cone_obj.phi_max,
                             scale=norm(cdp.pivot_CoM),
                             inc=inc)

    # Create the PDB file.
    print("\nGenerating the PDB file.")
    pdb_file = open_write_file(file, dir, force=force)
    structure.write_pdb(pdb_file)
    pdb_file.close()
Пример #2
0
def cone_pdb(cone_type=None, scale=1.0, file=None, dir=None, force=False):
    """Create a PDB file containing a geometric object representing the various cone models.

    Currently the only cone types supported are 'diff in cone' and 'diff on cone'.


    @param cone_type:   The type of cone model to represent.
    @type cone_type:    str
    @param scale:       The size of the geometric object is eqaul to the average pivot-CoM
                        vector length multiplied by this scaling factor.
    @type scale:        float
    @param file:        The name of the PDB file to create.
    @type file:         str
    @param dir:         The name of the directory to place the PDB file into.
    @type dir:          str
    @param force:       Flag which if set to True will cause any pre-existing file to be
                        overwritten.
    @type force:        int
    """

    # Test if the cone models have been determined.
    if cone_type == 'diff in cone':
        if not hasattr(cdp, 'S_diff_in_cone'):
            raise RelaxError("The diffusion in a cone model has not yet been determined.")
    elif cone_type == 'diff on cone':
        if not hasattr(cdp, 'S_diff_on_cone'):
            raise RelaxError("The diffusion on a cone model has not yet been determined.")
    else:
        raise RelaxError("The cone type " + repr(cone_type) + " is unknown.")

    # The number of increments for the filling of the cone objects.
    inc = 20

    # The rotation matrix.
    R = zeros((3, 3), float64)
    two_vect_to_R(array([0, 0, 1], float64), cdp.ave_pivot_CoM/norm(cdp.ave_pivot_CoM), R)

    # The isotropic cone object.
    if cone_type == 'diff in cone':
        angle = cdp.theta_diff_in_cone
    elif cone_type == 'diff on cone':
        angle = cdp.theta_diff_on_cone
    cone_obj = Iso_cone(angle)

    # Create the structural object.
    structure = Internal()

    # Add a structure.
    structure.add_molecule(name='cone')

    # Alias the single molecule from the single model.
    mol = structure.structural_data[0].mol[0]

    # Add the pivot point.
    mol.atom_add(pdb_record='HETATM', atom_num=1, atom_name='R', res_name='PIV', res_num=1, pos=cdp.pivot_point, element='C')

    # Generate the average pivot-CoM vectors.
    print("\nGenerating the average pivot-CoM vectors.")
    sim_vectors = None
    if hasattr(cdp, 'ave_pivot_CoM_sim'):
        sim_vectors = cdp.ave_pivot_CoM_sim
    res_num = generate_vector_residues(mol=mol, vector=cdp.ave_pivot_CoM, atom_name='Ave', res_name_vect='AVE', sim_vectors=sim_vectors, res_num=2, origin=cdp.pivot_point, scale=scale)

    # Generate the cone outer edge.
    print("\nGenerating the cone outer edge.")
    cap_start_atom = mol.atom_num[-1]+1
    cone_edge(mol=mol, cone_obj=cone_obj, res_name='CON', res_num=3, apex=cdp.pivot_point, R=R, scale=norm(cdp.pivot_CoM), inc=inc)

    # Generate the cone cap, and stitch it to the cone edge.
    if cone_type == 'diff in cone':
        print("\nGenerating the cone cap.")
        cone_start_atom = mol.atom_num[-1]+1
        generate_vector_dist(mol=mol, res_name='CON', res_num=3, centre=cdp.pivot_point, R=R, phi_max_fn=cone_obj.phi_max, scale=norm(cdp.pivot_CoM), inc=inc)

    # Create the PDB file.
    print("\nGenerating the PDB file.")
    pdb_file = open_write_file(file, dir, force=force)
    structure.write_pdb(pdb_file)
    pdb_file.close()
Пример #3
0
def add_axes(structure=None, representation=None, size=None, sims=False):
    """Add the axis system for the current frame order model to the structural object.

    @keyword structure:         The internal structural object to add the rotor objects to.
    @type structure:            lib.structure.internal.object.Internal instance
    @keyword representation:    The representation to create.  If this is set to None or 'A', the standard representation will be created.  If set to 'B', the axis system will be inverted.
    @type representation:       None or str
    @keyword size:              The size of the geometric object in Angstroms.
    @type size:                 float
    @keyword sims:              A flag which if True will add the Monte Carlo simulation rotors to the structural object.  There must be one model for each Monte Carlo simulation already present in the structural object.
    @type sims:                 bool
    """

    # Create the molecule.
    mol_name = 'axes'
    structure.add_molecule(name=mol_name)

    # The transformation matrix (identity matrix or inversion matrix).
    if representation == 'B':
        T = -eye(3)
    else:
        T = eye(3)

    # The models to loop over.
    model_nums = [None]
    sim_indices = [None]
    if sims:
        model_nums = [i + 1 for i in range(cdp.sim_number)]
        sim_indices = list(range(cdp.sim_number))

    # Loop over the models.
    for i in range(len(model_nums)):
        # Alias the molecule.
        mol = structure.get_molecule(mol_name, model=model_nums[i])

        # The pivot points.
        pivot1 = generate_pivot(order=1,
                                sim_index=sim_indices[i],
                                pdb_limit=True)
        pivot2 = generate_pivot(order=2,
                                sim_index=sim_indices[i],
                                pdb_limit=True)

        # A single z-axis, when no rotor object is present.
        if cdp.model in [MODEL_ISO_CONE_TORSIONLESS]:
            # Print out.
            print("\nGenerating the z-axis system.")

            # The axis.
            if sims:
                axis = create_rotor_axis_spherical(
                    theta=cdp.axis_theta_sim[sim_indices[i]],
                    phi=cdp.axis_phi_sim[sim_indices[i]])
            else:
                axis = create_rotor_axis_spherical(theta=cdp.axis_theta,
                                                   phi=cdp.axis_phi)
            print(("Central axis: %s." % axis))

            # Transform the central axis.
            axis = dot(T, axis)

            # Generate the axis vectors.
            print("\nGenerating the axis vectors.")
            res_num = generate_vector_residues(mol=mol,
                                               vector=axis,
                                               atom_name='z-ax',
                                               res_name_vect='AXE',
                                               res_num=2,
                                               origin=pivot1,
                                               scale=size)

        # The z-axis connecting two motional modes.
        elif cdp.model in [MODEL_DOUBLE_ROTOR]:
            # Printout.
            print("\nGenerating the z-axis linking the two pivot points.")

            # The axis.
            axis = pivot1 - pivot2
            print(("Interconnecting axis: %s." % axis))

            # Generate the axis vectors.
            print("\nGenerating the axis vectors.")
            res_num = generate_vector_residues(mol=mol,
                                               vector=axis,
                                               atom_name='z-ax',
                                               res_name_vect='AXE',
                                               res_num=1,
                                               origin=pivot2)

        # The full axis system.
        elif cdp.model in MODEL_LIST_PSEUDO_ELLIPSE:
            # Print out.
            print("\nGenerating the full axis system.")

            # Add the pivot point.
            mol.atom_add(atom_num=1,
                         atom_name='R',
                         res_name='AXE',
                         res_num=1,
                         pos=pivot1,
                         element='C',
                         pdb_record='HETATM')

            # The axis system.
            axes = generate_axis_system(sim_index=sim_indices[i])

            # Rotations and inversions.
            axes = dot(T, axes)

            # The axes to create.
            label = ['x', 'y']
            if cdp.model in [MODEL_PSEUDO_ELLIPSE_TORSIONLESS]:
                label = ['x', 'y', 'z']

            # Generate the axis vectors.
            print("\nGenerating the axis vectors.")
            for j in range(len(label)):
                res_num = generate_vector_residues(mol=mol,
                                                   vector=axes[:, j],
                                                   atom_name='%s-ax' %
                                                   label[j],
                                                   res_name_vect='AXE',
                                                   res_num=2,
                                                   origin=pivot1,
                                                   scale=size)
Пример #4
0
def add_axes(structure=None, representation=None, size=None, sims=False):
    """Add the axis system for the current frame order model to the structural object.

    @keyword structure:         The internal structural object to add the rotor objects to.
    @type structure:            lib.structure.internal.object.Internal instance
    @keyword representation:    The representation to create.  If this is set to None or 'A', the standard representation will be created.  If set to 'B', the axis system will be inverted.
    @type representation:       None or str
    @keyword size:              The size of the geometric object in Angstroms.
    @type size:                 float
    @keyword sims:              A flag which if True will add the Monte Carlo simulation rotors to the structural object.  There must be one model for each Monte Carlo simulation already present in the structural object.
    @type sims:                 bool
    """

    # Create the molecule.
    mol_name = 'axes'
    structure.add_molecule(name=mol_name)

    # The transformation matrix (identity matrix or inversion matrix).
    if representation == 'B':
        T = -eye(3)
    else:
        T = eye(3)

    # The models to loop over.
    model_nums = [None]
    sim_indices = [None]
    if sims:
        model_nums = [i+1 for i in range(cdp.sim_number)]
        sim_indices = list(range(cdp.sim_number))

    # Loop over the models.
    for i in range(len(model_nums)):
        # Alias the molecule.
        mol = structure.get_molecule(mol_name, model=model_nums[i])

        # The pivot points.
        pivot1 = generate_pivot(order=1, sim_index=sim_indices[i], pdb_limit=True)
        pivot2 = generate_pivot(order=2, sim_index=sim_indices[i], pdb_limit=True)

        # A single z-axis, when no rotor object is present.
        if cdp.model in [MODEL_ISO_CONE_TORSIONLESS]:
            # Print out.
            print("\nGenerating the z-axis system.")

            # The axis.
            if sims:
                axis = create_rotor_axis_spherical(theta=cdp.axis_theta_sim[sim_indices[i]], phi=cdp.axis_phi_sim[sim_indices[i]])
            else:
                axis = create_rotor_axis_spherical(theta=cdp.axis_theta, phi=cdp.axis_phi)
            print(("Central axis: %s." % axis))

            # Transform the central axis.
            axis = dot(T, axis)

            # Generate the axis vectors.
            print("\nGenerating the axis vectors.")
            res_num = generate_vector_residues(mol=mol, vector=axis, atom_name='z-ax', res_name_vect='AXE', res_num=2, origin=pivot1, scale=size)

        # The z-axis connecting two motional modes.
        elif cdp.model in [MODEL_DOUBLE_ROTOR]:
            # Printout.
            print("\nGenerating the z-axis linking the two pivot points.")

            # The axis.
            axis = pivot1 - pivot2
            print(("Interconnecting axis: %s." % axis))

            # Generate the axis vectors.
            print("\nGenerating the axis vectors.")
            res_num = generate_vector_residues(mol=mol, vector=axis, atom_name='z-ax', res_name_vect='AXE', res_num=1, origin=pivot2)

        # The full axis system.
        elif cdp.model in MODEL_LIST_PSEUDO_ELLIPSE:
            # Print out.
            print("\nGenerating the full axis system.")

            # Add the pivot point.
            mol.atom_add(atom_num=1, atom_name='R', res_name='AXE', res_num=1, pos=pivot1, element='C', pdb_record='HETATM')

            # The axis system.
            axes = generate_axis_system(sim_index=sim_indices[i])

            # Rotations and inversions.
            axes = dot(T, axes)

            # The axes to create.
            label = ['x', 'y']
            if cdp.model in [MODEL_PSEUDO_ELLIPSE_TORSIONLESS]:
                label = ['x', 'y', 'z']

            # Generate the axis vectors.
            print("\nGenerating the axis vectors.")
            for j in range(len(label)):
                res_num = generate_vector_residues(mol=mol, vector=axes[:, j], atom_name='%s-ax'%label[j], res_name_vect='AXE', res_num=2, origin=pivot1, scale=size)
Пример #5
0
def diffusion_tensor(mol=None, tensor=None, tensor_diag=None, diff_type=None, rotation=None, axes=None, sim_axes=None, com=None, scale=1.8e-6):
    """Create the structural representation of the diffusion tensor.

    @keyword mol:           The molecule container.
    @type mol:              MolContainer instance
    @keyword tensor:        The diffusion tensor.
    @type tensor:           numpy rank-2, 3D array
    @keyword tensor_diag:   The diagonalised diffusion tensor in tensor frame.
    @type tensor_diag:      numpy rank-2, 3D array
    @keyword diff_type:     The type of diffusion tensor.  This can be one of 'sphere', 'oblate', 'prolate', 'ellipsoid'.
    @type diff_type:        str
    @keyword rotation:      The diffusion tensor rotation matrix.
    @type rotation:         numpy rank-2, 3D array
    @keyword axes:          The axis system of the tensor.  For the spheroids this is one vector, for the ellipsoid it should be three vectors.
    @type axes:             list of numpy rank-1, 3D arrays
    @keyword sim_axes:      The axis systems of the tensor for each simulation.  For the spheroids this is one vector, for the ellipsoid it should be three vectors.  The first dimension is the axis type (x, y, or z), the second is the simulation, and the third is the vector.
    @type sim_axes:         None or list of lists of numpy rank-1, 3D arrays
    @keyword com:           The centre of mass of the diffusion structure.
    @type com:              numpy rank-1, 3D array
    @keyword scale:         The scaling factor for the diffusion tensor.
    @type scale:            float
    """

    # Initialise.
    #############

    # Initialise the residue number.
    res_num = 1

    # Add the central atom.
    mol.atom_add(pdb_record='HETATM', atom_num=1, atom_name='R', res_name='COM', res_num=res_num, pos=com, segment_id=None, element='C')

    # Increment the residue number.
    res_num = res_num + 1


    # Vector distribution.
    ######################

    # Print out.
    print("\nGenerating the geometric object.")

    # Swap the x and y axes for the prolate spheroid (the vector distributions are centred on the z-axis).
    if diff_type == 'prolate':
        # 90 deg rotation about the diffusion frame z-axis.
        z_rot = array([[  0, -1,  0],
                       [  1,  0,  0],
                       [  0,  0,  1]], float64)

        # Rotate the tensor and rotation matrix.
        rotation = dot(transpose(rotation), z_rot)
        tensor = dot(z_rot, dot(tensor_diag, transpose(z_rot)))
        tensor = dot(rotation, dot(tensor, transpose(rotation)))

    # Swap the x and z axes for the oblate spheroid (the vector distributions are centred on the z-axis).
    if diff_type == 'oblate':
        # 90 deg rotation about the diffusion frame y-axis.
        y_rot = array([[  0,  0,  1],
                       [  0,  1,  0],
                       [ -1,  0,  0]], float64)

        # Rotate the tensor and rotation matrix.
        rotation = dot(transpose(rotation), y_rot)
        tensor = dot(y_rot, dot(tensor_diag, transpose(y_rot)))
        tensor = dot(rotation, dot(tensor, transpose(rotation)))

    # The distribution.
    generate_vector_dist(mol=mol, res_name='TNS', res_num=res_num, centre=com, R=rotation, warp=tensor, scale=scale, inc=20)

    # Increment the residue number.
    res_num = res_num + 1


    # Axes of the tensor.
    #####################

    # Create the unique axis of the spheroid.
    if diff_type in ['oblate', 'prolate']:
        # Print out.
        print("\nGenerating the unique axis of the diffusion tensor.")
        print("    Scaling factor:                      " + repr(scale))

        # Generate the axes representation.
        res_num = generate_vector_residues(mol=mol, vector=axes[0], atom_name='Dpar', res_name_vect='AXS', sim_vectors=sim_axes[0], res_num=res_num, origin=com, scale=scale, neg=True)


    # Create the three axes of the ellipsoid.
    if diff_type == 'ellipsoid':
        # Print out.
        print("Generating the three axes of the ellipsoid.")
        print("    Scaling factor:                      " + repr(scale))

        # Generate the axes representation.
        res_num = generate_vector_residues(mol=mol, vector=axes[0], atom_name='Dx', res_name_vect='AXS', sim_vectors=sim_axes[0], res_num=res_num, origin=com, scale=scale, neg=True)
        res_num = generate_vector_residues(mol=mol, vector=axes[1], atom_name='Dy', res_name_vect='AXS', sim_vectors=sim_axes[1], res_num=res_num, origin=com, scale=scale, neg=True)
        res_num = generate_vector_residues(mol=mol, vector=axes[2], atom_name='Dz', res_name_vect='AXS', sim_vectors=sim_axes[2], res_num=res_num, origin=com, scale=scale, neg=True)