Package pipe_control :: Module paramag
[hide private]
[frames] | no frames]

Source Code for Module pipe_control.paramag

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2013 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  # Module docstring. 
 23  """Module for the manipulation of paramagnetic data.""" 
 24   
 25  # Python module imports. 
 26  from numpy import array, float64, zeros 
 27   
 28  # relax module imports. 
 29  from lib.errors import RelaxError 
 30  from pipe_control import pipes 
 31  from pipe_control.mol_res_spin import spin_loop 
 32   
 33   
34 -def centre(pos=None, atom_id=None, pipe=None, verbosity=1, fix=True, ave_pos=False, force=False):
35 """Specify the atom in the loaded structure corresponding to the paramagnetic centre. 36 37 @keyword pos: The atomic position. If set, the atom_id string will be ignored. 38 @type pos: list of float 39 @keyword atom_id: The atom identification string. 40 @type atom_id: str 41 @keyword pipe: An alternative data pipe to extract the paramagnetic centre from. 42 @type pipe: None or str 43 @keyword verbosity: The amount of information to print out. The bigger the number, the more information. 44 @type verbosity: int 45 @keyword fix: A flag which if False causes the paramagnetic centre to be optimised during minimisation. 46 @type fix: bool 47 @keyword ave_pos: A flag which if True causes the atomic positions from multiple models to be averaged. 48 @type ave_pos: bool 49 @keyword force: A flag which if True will cause the current paramagnetic centre to be overwritten. 50 @type force: bool 51 """ 52 53 # The data pipe. 54 if pipe == None: 55 pipe = pipes.cdp_name() 56 57 # Test the data pipe. 58 pipes.test(pipe) 59 60 # Get the data pipes. 61 source_dp = pipes.get_pipe(pipe) 62 63 # Test the centre has already been set. 64 if pos != None and not force and hasattr(cdp, 'paramagnetic_centre'): 65 raise RelaxError("The paramagnetic centre has already been set to the coordinates " + repr(cdp.paramagnetic_centre) + ".") 66 67 # The fixed flag. 68 if fix: 69 print("The paramagnetic centre position will be fixed during optimisation.") 70 else: 71 print("The paramagnetic centre position will be optimised.") 72 cdp.paramag_centre_fixed = fix 73 74 # Position is supplied. 75 if pos != None: 76 centre = array(pos) 77 num_pos = 1 78 full_pos_list = [] 79 80 # Position from a loaded structure. 81 elif atom_id: 82 # Get the positions. 83 centre = zeros(3, float64) 84 full_pos_list = [] 85 num_pos = 0 86 for spin, spin_id in spin_loop(atom_id, pipe=pipe, return_id=True): 87 # No atomic positions. 88 if not hasattr(spin, 'pos'): 89 continue 90 91 # Spin position list. 92 if isinstance(spin.pos[0], float) or isinstance(spin.pos[0], float64): 93 pos_list = [spin.pos] 94 else: 95 pos_list = spin.pos 96 97 # Loop over the model positions. 98 for pos in pos_list: 99 full_pos_list.append(pos) 100 centre = centre + array(pos) 101 num_pos = num_pos + 1 102 103 # No positional information! 104 if not num_pos: 105 raise RelaxError("No positional information could be found for the spin '%s'." % atom_id) 106 107 # No position - so simply exit the function. 108 else: 109 return 110 111 # Averaging. 112 centre = centre / float(num_pos) 113 114 # Print out. 115 if verbosity: 116 print("Paramagnetic centres located at:") 117 for pos in full_pos_list: 118 print(" [%8.3f, %8.3f, %8.3f]" % (pos[0], pos[1], pos[2])) 119 print("\nAverage paramagnetic centre located at:") 120 print(" [%8.3f, %8.3f, %8.3f]" % (centre[0], centre[1], centre[2])) 121 122 # Set the centre (place it into the current data pipe). 123 if ave_pos: 124 if verbosity: 125 print("\nUsing the average paramagnetic position.") 126 cdp.paramagnetic_centre = centre 127 else: 128 if verbosity: 129 print("\nUsing all paramagnetic positions.") 130 cdp.paramagnetic_centre = full_pos_list
131