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

Source Code for Module pipe_control.paramag

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