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