1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  """Module for the manipulation of paramagnetic data.""" 
 25   
 26   
 27  from numpy import array, float64, zeros 
 28   
 29   
 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       
 56      if pipe == None: 
 57          pipe = pipes.cdp_name() 
 58   
 59       
 60      check_pipe(pipe) 
 61   
 62       
 63      source_dp = pipes.get_pipe(pipe) 
 64   
 65       
 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       
 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       
 77      if pos is not None: 
 78          centre = array(pos) 
 79          num_pos = 1 
 80          full_pos_list = [] 
 81   
 82       
 83      elif atom_id: 
 84           
 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               
 90              if not hasattr(spin, 'pos'): 
 91                  continue 
 92       
 93               
 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               
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           
106          if not num_pos: 
107              raise RelaxError("No positional information could be found for the spin '%s'." % atom_id) 
108   
109       
110      else: 
111          return 
112   
113       
114      centre = centre / float(num_pos) 
115   
116       
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       
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