Example #1
0
def cone(mol=None, cone_obj=None, start_res=1, apex=None, axis=None, R=None, inc=None, scale=30.0, distribution='regular', axis_flag=True):
    """Create a structural representation of the given cone object.

    @keyword mol:           The molecule container.
    @type mol:              MolContainer instance
    @keyword cone_obj:      The cone object.  This should provide the limit_check() method with determines the limits of the distribution accepting two arguments, the polar angle phi and the azimuthal angle theta, and return True if the point is in the limits or False if outside.  It should also provide the theta_max() method for returning the theta value for the given phi, the phi_max() method for returning the phi value for the given theta.
    @type cone_obj:         class instance
    @keyword start_res:     The starting residue number.
    @type start_res:        str
    @keyword apex:          The apex of the cone.
    @type apex:             rank-1, 3D numpy array
    @keyword axis:          The central axis of the cone.  If not supplied, the z-axis will be used.
    @type axis:             rank-1, 3D numpy array
    @keyword R:             The rotation matrix.
    @type R:                rank-2, 3D numpy array
    @keyword inc:           The increment number used to determine the number of latitude and longitude lines.
    @type inc:              int
    @keyword scale:         The scaling factor to stretch the unit cone by.
    @type scale:            float
    @keyword distribution:  The type of point distribution to use.  This can be 'uniform' or 'regular'.
    @type distribution:     str
    @keyword axis_flag:     A flag which if True will create the cone's axis.
    @type axis_flag:        bool
    """

    # The cone axis default of the z-axis.
    if not axis:
        axis = array([0, 0, 1], float64)

    # No rotation.
    if R is None:
        R = eye(3)

    # The first atom number.
    start_atom = 1
    if hasattr(mol, 'atom_num') and len(mol.atom_num):
        start_atom = mol.atom_num[-1]+1

    # The axis.
    if axis_flag:
        # Add the apex (or centre point).
        mol.atom_add(pdb_record='HETATM', atom_num=start_atom, atom_name='R', res_name='CNC', res_num=start_res, pos=apex, element='C')

        # Generate the axis vectors.
        print("\nGenerating the axis vectors.")
        res_num = generate_vector_residues(mol=mol, vector=dot(R, axis), atom_name='Axis', res_name_vect='CNX', res_num=start_res+1, origin=apex, scale=scale)

    # Generate the cone outer edge.
    print("\nGenerating the cone outer edge.")
    edge_start_atom = 1
    if hasattr(mol, 'atom_num') and len(mol.atom_num):
        edge_start_atom = mol.atom_num[-1]+1
    cone_edge(mol=mol, cone_obj=cone_obj, res_name='CNE', res_num=start_res+2, apex=apex, R=R, scale=scale, inc=inc, distribution=distribution)

    # Generate the cone cap, and stitch it to the cone edge.
    print("\nGenerating the cone cap.")
    cone_start_atom = mol.atom_num[-1]+1
    generate_vector_dist(mol=mol, res_name='CON', res_num=start_res+3, centre=apex, R=R, phi_max_fn=cone_obj.phi_max, scale=scale, inc=inc, distribution=distribution)
Example #2
0
def cone(mol=None, cone_obj=None, start_res=1, apex=None, axis=None, R=None, inc=None, scale=30.0, distribution='regular', axis_flag=True):
    """Create a structural representation of the given cone object.

    @keyword mol:           The molecule container.
    @type mol:              MolContainer instance
    @keyword cone_obj:      The cone object.  This should provide the limit_check() method with determines the limits of the distribution accepting two arguments, the polar angle phi and the azimuthal angle theta, and return True if the point is in the limits or False if outside.  It should also provide the theta_max() method for returning the theta value for the given phi, the phi_max() method for returning the phi value for the given theta.
    @type cone_obj:         class instance
    @keyword start_res:     The starting residue number.
    @type start_res:        str
    @keyword apex:          The apex of the cone.
    @type apex:             rank-1, 3D numpy array
    @keyword axis:          The central axis of the cone.  If not supplied, the z-axis will be used.
    @type axis:             rank-1, 3D numpy array
    @keyword R:             The rotation matrix.
    @type R:                rank-2, 3D numpy array
    @keyword inc:           The increment number used to determine the number of latitude and longitude lines.
    @type inc:              int
    @keyword scale:         The scaling factor to stretch the unit cone by.
    @type scale:            float
    @keyword distribution:  The type of point distribution to use.  This can be 'uniform' or 'regular'.
    @type distribution:     str
    @keyword axis_flag:     A flag which if True will create the cone's axis.
    @type axis_flag:        bool
    """

    # The cone axis default of the z-axis.
    if not axis:
        axis = array([0, 0, 1], float64)

    # No rotation.
    if R is None:
        R = eye(3)

    # The first atom number.
    start_atom = 1
    if hasattr(mol, 'atom_num') and len(mol.atom_num):
        start_atom = mol.atom_num[-1]+1

    # The axis.
    if axis_flag:
        # Add the apex (or centre point).
        mol.atom_add(pdb_record='HETATM', atom_num=start_atom, atom_name='R', res_name='CNC', res_num=start_res, pos=apex, element='C')

        # Generate the axis vectors.
        print("\nGenerating the axis vectors.")
        res_num = generate_vector_residues(mol=mol, vector=dot(R, axis), atom_name='Axis', res_name_vect='CNX', res_num=start_res+1, origin=apex, scale=scale)

    # Generate the cone outer edge.
    print("\nGenerating the cone outer edge.")
    edge_start_atom = 1
    if hasattr(mol, 'atom_num') and len(mol.atom_num):
        edge_start_atom = mol.atom_num[-1]+1
    cone_edge(mol=mol, cone_obj=cone_obj, res_name='CNE', res_num=start_res+2, apex=apex, R=R, scale=scale, inc=inc, distribution=distribution)

    # Generate the cone cap, and stitch it to the cone edge.
    print("\nGenerating the cone cap.")
    cone_start_atom = mol.atom_num[-1]+1
    generate_vector_dist(mol=mol, res_name='CON', res_num=start_res+3, centre=apex, R=R, phi_max_fn=cone_obj.phi_max, scale=scale, inc=inc, distribution=distribution)
Example #3
0
File: uf.py Project: tlinnet/relax
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()
Example #4
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()
Example #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)