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()
def pdb(r=1.02, file_name='uniform.pdb', inc=None): """Create the bond vector distribution and save the PDB file.""" # Create the structural object. structure = Internal() # Add a molecule. structure.add_molecule(name='dist') # Alias the single molecule from the single model. mol = structure.structural_data[0].mol[0] # Get the polar and azimuthal angles for the distribution. phi, theta = angles_uniform(inc) # Get the uniform vector distribution. vectors = vect_dist_spherical_angles(inc=inc, distribution='uniform') # Loop over the radial array of vectors (change in longitude). atom_num = 1 new_vectors = [] for i in range(len(theta)): # Loop over the vectors of the radial array (change in latitude). for j in range(len(phi)): # The index. index = i + j * len(theta) # The atomic positions. pos1 = vectors[index] * 10 pos2 = pos1 + vectors[index] * r # Store the rearranged vector (truncated as in the PDB). trunc_vect = zeros(3, float64) for k in range(3): trunc_vect[k] = float("%.3f" % pos2[k]) - float( "%.3f" % pos1[k]) new_vectors.append(trunc_vect) # Residue number. res = (atom_num + 1) / 2 # Add the vector as a N-H atom pair. mol.atom_add(pdb_record='ATOM', atom_num=atom_num, atom_name='N', res_name=AA_TABLE[SEQ[index]].upper(), res_num=res, pos=pos1, element='N') mol.atom_add(pdb_record='ATOM', atom_num=atom_num + 1, atom_name='H', res_name=AA_TABLE[SEQ[index]].upper(), res_num=res, pos=pos2, element='H') # Connect. mol.atom_connect(atom_num - 1, atom_num) # Move 2 atoms forwards. atom_num += 2 # The PDB file. file = open_write_file(file_name, force=True) structure.write_pdb(file) file.close() # Return the vectors in the diffusion frame. return new_vectors
def create_rotor_pdb(file=None, dir=None, rotor_angle=None, axis=None, axis_pt=True, centre=None, span=2e-9, blade_length=5e-10, force=False, staggered=False): """Create a PDB representation of a rotor motional model. @keyword file: The name of the PDB file to create. @type file: str @keyword dir: The name of the directory to place the PDB file into. @type dir: str @keyword rotor_angle: The angle of the rotor motion in degrees. @type rotor_angle: float @keyword axis: The vector defining the rotor axis. @type axis: numpy rank-1, 3D array @keyword axis_pt: A point lying anywhere on the rotor axis. This is used to define the position of the axis in 3D space. @type axis_pt: numpy rank-1, 3D array @keyword centre: The central point of the representation. If this point is not on the rotor axis, then the closest point on the axis will be used for the centre. @type centre: numpy rank-1, 3D array @keyword span: The distance from the central point to the rotor blades (meters). @type span: float @keyword blade_length: The length of the representative rotor blades. @type blade_length: float @keyword force: A flag which if set will overwrite any pre-existing file. @type force: bool @keyword staggered: A flag which if True will cause the rotor blades to be staggered. This is used to avoid blade overlap. @type staggered: bool """ # Test if the current pipe exists. check_pipe() # Convert the angle to radians. rotor_angle = rotor_angle / 360.0 * 2.0 * pi # Create the structural object. structure = Internal() # Generate the rotor object. rotor(structure=structure, rotor_angle=rotor_angle, axis=axis, axis_pt=axis_pt, centre=centre, span=span, blade_length=blade_length, staggered=staggered) # Print out. print("\nGenerating the PDB file.") # Open the PDB file for writing. tensor_pdb_file = open_write_file(file, dir, force=force) # Write the data. structure.write_pdb(tensor_pdb_file) # Close the file. tensor_pdb_file.close() # Add the file to the results file list. if not hasattr(cdp, 'result_files'): cdp.result_files = [] if dir == None: dir = getcwd() cdp.result_files.append( ['rotor_pdb', 'Rotor PDB', get_file_path(file, dir)]) status.observers.result_file.notify()
def create_vector_dist(length=None, symmetry=True, file=None, dir=None, force=False): """Create a PDB representation of the vector distribution. @keyword length: The length to set the vectors to in the PDB file. @type length: float @keyword symmetry: The symmetry flag which if set will create a second PDB chain 'B' which is the same as chain 'A' but with the vectors reversed. @type symmetry: bool @keyword file: The name of the PDB file to create. @type file: str @keyword dir: The name of the directory to place the PDB file into. @type dir: str @keyword force: Flag which if set will overwrite any pre-existing file. @type force: bool """ # Test if the current pipe exists. check_pipe() # Test if a structure has been loaded. if not hasattr(cdp, 'structure') or not cdp.structure.num_models() > 0: raise RelaxNoPdbError # Test if sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Test if unit vectors exist. vectors = False for interatom in interatomic_loop(): if hasattr(interatom, 'vector'): vectors = True break if not vectors: raise RelaxNoVectorsError # Initialise. ############# # Create the structural object. structure = Internal() # Add a structure. structure.add_molecule(name='vector_dist') # Alias the single molecule from the single model. mol = structure.structural_data[0].mol[0] # Initialise the residue and atom numbers. res_num = 1 atom_num = 1 # Centre of mass. ################# # Calculate the centre of mass. R = pipe_centre_of_mass() # Increment the residue number. res_num = res_num + 1 # The vectors. ############## # Loop over the interatomic data containers. for interatom in interatomic_loop(): # Get the spins. spin1 = return_spin(spin_hash=interatom._spin_hash1) spin2 = return_spin(spin_hash=interatom._spin_hash2) # Skip deselected spin systems. if not spin1.select or not spin2.select: continue # Skip containers missing vectors. if not hasattr(interatom, 'vector'): continue # Scale the vector. vector = interatom.vector * length * 1e10 # Add the first spin as the central atom. mol.atom_add(pdb_record='ATOM', atom_num=atom_num, atom_name=spin1.name, res_name=spin1._res_name, chain_id='A', res_num=spin1._res_num, pos=R, segment_id=None, element=spin1.element) # Add the second spin as the end atom. mol.atom_add(pdb_record='ATOM', atom_num=atom_num + 1, atom_name=spin2.name, res_name=spin2._res_name, chain_id='A', res_num=spin2._res_num, pos=R + vector, segment_id=None, element=spin2.element) # Connect the two atoms. mol.atom_connect(index1=atom_num - 1, index2=atom_num) # Increment the atom number. atom_num = atom_num + 2 # Symmetry chain. if symmetry: # Loop over the interatomic data containers. for interatom in interatomic_loop(): # Get the spins. spin1 = return_spin(spin_hash=interatom._spin_hash1) spin2 = return_spin(spin_hash=interatom._spin_hash2) # Skip deselected spin systems. if not spin1.select or not spin2.select: continue # Skip containers missing vectors. if not hasattr(interatom, 'vector'): continue # Scale the vector. vector = interatom.vector * length * 1e10 # Add the first spin as the central atom. mol.atom_add(pdb_record='ATOM', atom_num=atom_num, atom_name=spin1.name, res_name=spin1._res_name, chain_id='B', res_num=spin1._res_num, pos=R, segment_id=None, element=spin1.element) # Add the second spin as the end atom. mol.atom_add(pdb_record='ATOM', atom_num=atom_num + 1, atom_name=spin2.name, res_name=spin2._res_name, chain_id='B', res_num=spin2._res_num, pos=R - vector, segment_id=None, element=spin2.element) # Connect the two atoms. mol.atom_connect(index1=atom_num - 1, index2=atom_num) # Increment the atom number. atom_num = atom_num + 2 # Create the PDB file. ###################### # Print out. print("\nGenerating the PDB file.") # Open the PDB file for writing. tensor_pdb_file = open_write_file(file, dir, force=force) # Write the data. structure.write_pdb(tensor_pdb_file) # Close the file. tensor_pdb_file.close() # Add the file to the results file list. if not hasattr(cdp, 'result_files'): cdp.result_files = [] if dir == None: dir = getcwd() cdp.result_files.append([ 'vector_dist_pdb', 'Vector distribution PDB', get_file_path(file, dir) ]) status.observers.result_file.notify()
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()
# GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # # # ############################################################################### # Module docstring. """Create a PDB representation for the real pivot point used to generate the data.""" # relax module imports. from lib.io import open_write_file from lib.structure.internal.object import Internal # Create the structural object. structure = Internal() # Add a molecule. structure.add_molecule(name='piv') # Alias the single molecule from the single model. mol = structure.structural_data[0].mol[0] # Add the original pivot. mol.atom_add(atom_name='N', res_name='PIV', res_num=1, pos=[37.254, 0.5, 16.7465], element='N') # Add the shifted pivot.
def from_xml(self, pipe_node, file_version=None, dir=None): """Read a pipe container XML element and place the contents into this pipe. @param pipe_node: The data pipe XML node. @type pipe_node: xml.dom.minidom.Element instance @keyword file_version: The relax XML version of the XML file. @type file_version: int @keyword dir: The name of the directory containing the results file (needed for loading external files). @type dir: str """ # Test if empty. if not self.is_empty(): raise RelaxFromXMLNotEmptyError(self.__class__.__name__) # Get the global data node, and fill the contents of the pipe. global_node = pipe_node.getElementsByTagName('global')[0] xml_to_object(global_node, self, file_version=file_version) # Backwards compatibility transformations. self._back_compat_hook(file_version) # Get the hybrid node (and its sub-node), and recreate the hybrid object. hybrid_node = pipe_node.getElementsByTagName('hybrid')[0] pipes_node = hybrid_node.getElementsByTagName('pipes')[0] setattr(self, 'hybrid_pipes', node_value_to_python(pipes_node.childNodes[0])) # Get the experimental information data nodes and, if they exist, fill the contents. exp_info_nodes = pipe_node.getElementsByTagName('exp_info') if exp_info_nodes: # Create the data container. self.exp_info = ExpInfo() # Fill its contents. self.exp_info.from_xml(exp_info_nodes[0], file_version=file_version) # Get the diffusion tensor data nodes and, if they exist, fill the contents. diff_tensor_nodes = pipe_node.getElementsByTagName('diff_tensor') if diff_tensor_nodes: # Create the diffusion tensor object. self.diff_tensor = DiffTensorData() # Fill its contents. self.diff_tensor.from_xml(diff_tensor_nodes[0], file_version=file_version) # Get the alignment tensor data nodes and, if they exist, fill the contents. align_tensor_nodes = pipe_node.getElementsByTagName('align_tensors') if align_tensor_nodes: # Create the alignment tensor object. self.align_tensors = AlignTensorList() # Fill its contents. self.align_tensors.from_xml(align_tensor_nodes[0], file_version=file_version) # Recreate the interatomic data structure (this needs to be before the 'mol' structure as the backward compatibility hooks can create interatomic data containers!). interatom_nodes = pipe_node.getElementsByTagName('interatomic') self.interatomic.from_xml(interatom_nodes, file_version=file_version) # Recreate the molecule, residue, and spin data structure. mol_nodes = pipe_node.getElementsByTagName('mol') self.mol.from_xml(mol_nodes, file_version=file_version) # Get the structural object nodes and, if they exist, fill the contents. str_nodes = pipe_node.getElementsByTagName('structure') if str_nodes: # Create the structural object. fail = False self.structure = Internal() # Fill its contents. if not fail: self.structure.from_xml(str_nodes[0], dir=dir, file_version=file_version)