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