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

Source Code for Module generic_fns.paramag

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