Author: bugman Date: Wed Oct 26 14:47:24 2011 New Revision: 14928 URL: http://svn.gna.org/viewcvs/relax?rev=14928&view=rev Log: Rearranged the back end of the structure.superimpose user function. This is just to shift more code into the 'superimpose' module. Modified: 1.3/generic_fns/structure/main.py 1.3/generic_fns/structure/superimpose.py Modified: 1.3/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/main.py?rev=14928&r1=14927&r2=14928&view=diff ============================================================================== --- 1.3/generic_fns/structure/main.py (original) +++ 1.3/generic_fns/structure/main.py Wed Oct 26 14:47:24 2011 @@ -37,7 +37,7 @@ from generic_fns.structure.api_base import Displacements from generic_fns.structure.internal import Internal from generic_fns.structure.scientific import Scientific_data -from generic_fns.structure.superimpose import kabsch +from generic_fns.structure.superimpose import fit_to_first from relax_errors import RelaxError, RelaxFileError, RelaxNoPdbError, RelaxNoSequenceError from relax_io import get_file_path, open_write_file, write_spin_data from relax_warnings import RelaxWarning, RelaxNoPDBFileWarning, RelaxZeroVectorWarning @@ -510,47 +510,28 @@ for model in cdp.structure.model_loop(): models.append(model.num) + # Assemble the atomic coordinates of all models. + coord = [] + for model in models: + coord.append([]) + for pos in cdp.structure.atom_loop(atom_id=atom_id, model_num=model, pos_flag=True): + coord[-1].append(pos[0]) + coord[-1] = array(coord[-1]) + # The different algorithms. if method == 'fit to mean': - superimpose_to_mean(models=models, atom_id=atom_id) + T, R, pivot = fit_to_mean(models=models, coord=coord) elif method == 'fit to first': - superimpose_to_first(models=models, atom_id=atom_id) - - -def superimpose_to_first(models=None, atom_id=None): - """Superimpose a set of structural models using the fit to first algorithm. - - @keyword models: The list of models to superimpose. - @type models: list of int - @keyword atom_id: The molecule, residue, and atom identifier string. This matches the spin ID string format. - @type atom_id: str or None - """ - - # Print out. - print("\nSuperimposition of structural models %s using the 'fit to first' algorithm." % models) - - # Assemble the atomic coordinates of the first model. - coord_to = [] - for pos in cdp.structure.atom_loop(atom_id=atom_id, model_num=models[0], pos_flag=True): - coord_to.append(pos[0]) - coord_to = array(coord_to) - - # Loop over the ending models. - for model in models[1:]: - # Assemble the atomic coordinates. - coord_from = [] - for pos in cdp.structure.atom_loop(atom_id=atom_id, model_num=model, pos_flag=True): - coord_from.append(pos[0]) - coord_from = array(coord_from) - - # Calculate the displacements (Kabsch algorithm). - trans_vect, trans_dist, R, axis, angle, pivot = kabsch(name_from='model %s'%models[0], name_to='model %s'%model, coord_from=coord_from, coord_to=coord_to) - + T, R, pivot = fit_to_first(models=models, coord=coord) + + + # Update to the new coordinates. + for i in range(len(models)): # Translate the molecule first (the rotational pivot is defined in the first model). - translate(T=trans_vect, model=model) + translate(T=T[i], model=models[i]) # Rotate the molecule. - rotate(R=R, origin=pivot, model=model) + rotate(R=R[i], origin=pivot[i], model=models[i]) def translate(T=None, model=None): Modified: 1.3/generic_fns/structure/superimpose.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/superimpose.py?rev=14928&r1=14927&r2=14928&view=diff ============================================================================== --- 1.3/generic_fns/structure/superimpose.py (original) +++ 1.3/generic_fns/structure/superimpose.py Wed Oct 26 14:47:24 2011 @@ -25,7 +25,7 @@ # Python module imports. from math import pi -from numpy import diag, dot, float64, outer, sign, transpose, zeros +from numpy import diag, dot, eye, float64, outer, sign, transpose, zeros from numpy.linalg import det, norm, svd # relax module import. @@ -46,6 +46,39 @@ # Return. return centroid + + +def fit_to_first(models=None, coord=None): + """Superimpose a set of structural models using the fit to first algorithm. + + @keyword models: The list of models to superimpose. + @type models: list of int + @keyword coord: The list of coordinates of all models to superimpose. The first index is the models, the second is the atomic positions, and the third is the xyz coordinates. + @type coord: list of numpy rank-2, Nx3 arrays + @return: The lists of translation vectors, rotation matrices, and rotation pivots. + @rtype: list of numpy rank-1 3D arrays, list of numpy rank-2 3D arrays, list of numpy rank-1 3D arrays + """ + + # Print out. + print("\nSuperimposition of structural models %s using the 'fit to first' algorithm." % models) + + # Init (there is no transformation for the first model). + T_list = [zeros(3, float64)] + R_list = [eye(3, dtype=float64)] + pivot_list = [zeros(3, float64)] + + # Loop over the ending models. + for i in range(1, len(models)): + # Calculate the displacements (Kabsch algorithm). + trans_vect, trans_dist, R, axis, angle, pivot = kabsch(name_from='model %s'%models[0], name_to='model %s'%models[i], coord_from=coord[i], coord_to=coord[0]) + + # Store the transforms. + T_list.append(trans_vect) + R_list.append(R) + pivot_list.append(pivot) + + # Return the transform data. + return T_list, R_list, pivot_list def kabsch(name_from=None, name_to=None, coord_from=None, coord_to=None, centroid=None, verbosity=1):