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

Source Code for Module generic_fns.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 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 the centre has already been set. 68 if pos != None and not force and hasattr(cdp, 'paramagnetic_centre'): 69 raise RelaxError("The paramagnetic centre has already been set to the coordinates " + repr(cdp.paramagnetic_centre) + ".") 70 71 # The fixed flag. 72 if fix: 73 print("The paramagnetic centre position will be fixed during optimisation.") 74 else: 75 print("The paramagnetic centre position will be optimised.") 76 cdp.paramag_centre_fixed = fix 77 78 # Position is supplied. 79 if pos != None: 80 centre = array(pos) 81 num_pos = 1 82 full_pos_list = [] 83 84 # Position from a loaded structure. 85 elif atom_id: 86 # Get the positions. 87 centre = zeros(3, float64) 88 full_pos_list = [] 89 num_pos = 0 90 for spin, spin_id in spin_loop(atom_id, pipe=pipe, return_id=True): 91 # No atomic positions. 92 if not hasattr(spin, 'pos'): 93 continue 94 95 # Spin position list. 96 if isinstance(spin.pos[0], float) or isinstance(spin.pos[0], float64): 97 pos_list = [spin.pos] 98 else: 99 pos_list = spin.pos 100 101 # Loop over the model positions. 102 for pos in pos_list: 103 full_pos_list.append(pos) 104 centre = centre + array(pos) 105 num_pos = num_pos + 1 106 107 # No positional information! 108 if not num_pos: 109 raise RelaxError("No positional information could be found for the spin '%s'." % atom_id) 110 111 # No position - so simply exit the function. 112 else: 113 return 114 115 # Averaging. 116 centre = centre / float(num_pos) 117 118 # Print out. 119 if verbosity: 120 print("Paramagnetic centres located at:") 121 for pos in full_pos_list: 122 print(" [%8.3f, %8.3f, %8.3f]" % (pos[0], pos[1], pos[2])) 123 print("\nAverage paramagnetic centre located at:") 124 print(" [%8.3f, %8.3f, %8.3f]" % (centre[0], centre[1], centre[2])) 125 126 # Set the centre (place it into the current data pipe). 127 if ave_pos: 128 if verbosity: 129 print("\nUsing the average paramagnetic position.") 130 cdp.paramagnetic_centre = centre 131 else: 132 if verbosity: 133 print("\nUsing all paramagnetic positions.") 134 cdp.paramagnetic_centre = full_pos_list
135