Package pipe_control :: Package structure :: Module geometric
[hide private]
[frames] | no frames]

Source Code for Module pipe_control.structure.geometric

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2013 Edward d'Auvergne                                   # 
  4  # Copyright (C) 2008 Sebastien Morin                                          # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from math import pi 
 25  from os import getcwd 
 26   
 27  # relax module imports. 
 28  from lib.errors import RelaxNoPdbError, RelaxNoSequenceError, RelaxNoVectorsError 
 29  from lib.io import get_file_path, open_write_file 
 30  from lib.structure.internal.object import Internal 
 31  from lib.structure.represent.rotor import rotor 
 32  from pipe_control.interatomic import interatomic_loop 
 33  from pipe_control.mol_res_spin import exists_mol_res_spin_data, return_spin 
 34  from pipe_control.pipes import check_pipe 
 35  from pipe_control.structure.mass import pipe_centre_of_mass 
 36  from status import Status; status = Status() 
 37   
 38   
39 -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):
40 """Create a PDB representation of a rotor motional model. 41 42 @keyword file: The name of the PDB file to create. 43 @type file: str 44 @keyword dir: The name of the directory to place the PDB file into. 45 @type dir: str 46 @keyword rotor_angle: The angle of the rotor motion in degrees. 47 @type rotor_angle: float 48 @keyword axis: The vector defining the rotor axis. 49 @type axis: numpy rank-1, 3D array 50 @keyword axis_pt: A point lying anywhere on the rotor axis. This is used to define the position of the axis in 3D space. 51 @type axis_pt: numpy rank-1, 3D array 52 @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. 53 @type centre: numpy rank-1, 3D array 54 @keyword span: The distance from the central point to the rotor blades (meters). 55 @type span: float 56 @keyword blade_length: The length of the representative rotor blades. 57 @type blade_length: float 58 @keyword force: A flag which if set will overwrite any pre-existing file. 59 @type force: bool 60 @keyword staggered: A flag which if True will cause the rotor blades to be staggered. This is used to avoid blade overlap. 61 @type staggered: bool 62 """ 63 64 # Test if the current pipe exists. 65 check_pipe() 66 67 # Convert the angle to radians. 68 rotor_angle = rotor_angle / 360.0 * 2.0 * pi 69 70 # Create the structural object. 71 structure = Internal() 72 73 # Generate the rotor object. 74 rotor(structure=structure, rotor_angle=rotor_angle, axis=axis, axis_pt=axis_pt, centre=centre, span=span, blade_length=blade_length, staggered=staggered) 75 76 # Print out. 77 print("\nGenerating the PDB file.") 78 79 # Open the PDB file for writing. 80 tensor_pdb_file = open_write_file(file, dir, force=force) 81 82 # Write the data. 83 structure.write_pdb(tensor_pdb_file) 84 85 # Close the file. 86 tensor_pdb_file.close() 87 88 # Add the file to the results file list. 89 if not hasattr(cdp, 'result_files'): 90 cdp.result_files = [] 91 if dir == None: 92 dir = getcwd() 93 cdp.result_files.append(['rotor_pdb', 'Rotor PDB', get_file_path(file, dir)]) 94 status.observers.result_file.notify()
95 96
97 -def create_vector_dist(length=None, symmetry=True, file=None, dir=None, force=False):
98 """Create a PDB representation of the vector distribution. 99 100 @keyword length: The length to set the vectors to in the PDB file. 101 @type length: float 102 @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. 103 @type symmetry: bool 104 @keyword file: The name of the PDB file to create. 105 @type file: str 106 @keyword dir: The name of the directory to place the PDB file into. 107 @type dir: str 108 @keyword force: Flag which if set will overwrite any pre-existing file. 109 @type force: bool 110 """ 111 112 # Test if the current pipe exists. 113 check_pipe() 114 115 # Test if a structure has been loaded. 116 if not hasattr(cdp, 'structure') or not cdp.structure.num_models() > 0: 117 raise RelaxNoPdbError 118 119 # Test if sequence data is loaded. 120 if not exists_mol_res_spin_data(): 121 raise RelaxNoSequenceError 122 123 # Test if unit vectors exist. 124 vectors = False 125 for interatom in interatomic_loop(): 126 if hasattr(interatom, 'vector'): 127 vectors = True 128 break 129 if not vectors: 130 raise RelaxNoVectorsError 131 132 133 # Initialise. 134 ############# 135 136 # Create the structural object. 137 structure = Internal() 138 139 # Add a structure. 140 structure.add_molecule(name='vector_dist') 141 142 # Alias the single molecule from the single model. 143 mol = structure.structural_data[0].mol[0] 144 145 # Initialise the residue and atom numbers. 146 res_num = 1 147 atom_num = 1 148 149 150 # Centre of mass. 151 ################# 152 153 # Calculate the centre of mass. 154 R = pipe_centre_of_mass() 155 156 # Increment the residue number. 157 res_num = res_num + 1 158 159 160 # The vectors. 161 ############## 162 163 # Loop over the interatomic data containers. 164 for interatom in interatomic_loop(): 165 # Get the spins. 166 spin1 = return_spin(spin_hash=interatom._spin_hash1) 167 spin2 = return_spin(spin_hash=interatom._spin_hash2) 168 169 # Skip deselected spin systems. 170 if not spin1.select or not spin2.select: 171 continue 172 173 # Skip containers missing vectors. 174 if not hasattr(interatom, 'vector'): 175 continue 176 177 # Scale the vector. 178 vector = interatom.vector * length * 1e10 179 180 # Add the first spin as the central atom. 181 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) 182 183 # Add the second spin as the end atom. 184 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) 185 186 # Connect the two atoms. 187 mol.atom_connect(index1=atom_num-1, index2=atom_num) 188 189 # Increment the atom number. 190 atom_num = atom_num + 2 191 192 # Symmetry chain. 193 if symmetry: 194 # Loop over the interatomic data containers. 195 for interatom in interatomic_loop(): 196 # Get the spins. 197 spin1 = return_spin(spin_hash=interatom._spin_hash1) 198 spin2 = return_spin(spin_hash=interatom._spin_hash2) 199 200 # Skip deselected spin systems. 201 if not spin1.select or not spin2.select: 202 continue 203 204 # Skip containers missing vectors. 205 if not hasattr(interatom, 'vector'): 206 continue 207 208 # Scale the vector. 209 vector = interatom.vector * length * 1e10 210 211 # Add the first spin as the central atom. 212 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) 213 214 # Add the second spin as the end atom. 215 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) 216 217 # Connect the two atoms. 218 mol.atom_connect(index1=atom_num-1, index2=atom_num) 219 220 # Increment the atom number. 221 atom_num = atom_num + 2 222 223 224 # Create the PDB file. 225 ###################### 226 227 # Print out. 228 print("\nGenerating the PDB file.") 229 230 # Open the PDB file for writing. 231 tensor_pdb_file = open_write_file(file, dir, force=force) 232 233 # Write the data. 234 structure.write_pdb(tensor_pdb_file) 235 236 # Close the file. 237 tensor_pdb_file.close() 238 239 # Add the file to the results file list. 240 if not hasattr(cdp, 'result_files'): 241 cdp.result_files = [] 242 if dir == None: 243 dir = getcwd() 244 cdp.result_files.append(['vector_dist_pdb', 'Vector distribution PDB', get_file_path(file, dir)]) 245 status.observers.result_file.notify()
246