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

Source Code for Module pipe_control.paramag

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