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

Source Code for Module generic_fns.paramag

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