Author: bugman Date: Mon Mar 18 17:25:54 2013 New Revision: 18864 URL: http://svn.gna.org/viewcvs/relax?rev=18864&view=rev Log: Split up the frame_order.pdb_model user function backend into three components. The main _pdb_model() method now consists of calls to three new methods _pdb_ave_pos(), _pdb_geometric_rep() and _pdb_distribution(). The _pdb_geometric_rep() method is simply the contents of the old _pdb_model() method and the two other methods are currently stubs. Modified: branches/frame_order_testing/specific_fns/frame_order.py Modified: branches/frame_order_testing/specific_fns/frame_order.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/specific_fns/frame_order.py?rev=18864&r1=18863&r2=18864&view=diff ============================================================================== --- branches/frame_order_testing/specific_fns/frame_order.py (original) +++ branches/frame_order_testing/specific_fns/frame_order.py Mon Mar 18 17:25:54 2013 @@ -946,10 +946,224 @@ return num + def _pdb_ave_pos(self, file=None, dir=None, force=False): + """Create a PDB file of the molecule with the moving domains shifted to the average position. + + @keyword file: The name of the file for the average molecule structure. + @type file: str + @keyword dir: The name of the directory to place the PDB file into. + @type dir: str + @keyword force: Flag which if set to True will cause any pre-existing file to be overwritten. + @type force: bool + """ + + + def _pdb_distribution(self, file=None, dir=None, force=False): + """Create a PDB file of a distribution of positions coving the full dynamics of the moving domain. + + @keyword file: The name of the file which will contain multiple models spanning the full dynamics distribution of the frame order model. + @type file: str + @keyword dir: The name of the directory to place the PDB file into. + @type dir: str + @keyword force: Flag which if set to True will cause any pre-existing file to be overwritten. + @type force: bool + """ + + + def _pdb_geometric_rep(self, file=None, dir=None, size=30.0, inc=36, force=False, neg_cone=True): + """Create a PDB file containing a geometric object representing the frame order dynamics. + + @keyword file: The name of the file of the PDB representation of the frame order dynamics to create. + @type file: str + @keyword dir: The name of the directory to place the PDB file into. + @type dir: str + @keyword size: The size of the geometric object in Angstroms. + @type size: float + @keyword inc: The number of increments for the filling of the cone objects. + @type inc: int + @keyword force: Flag which if set to True will cause any pre-existing file to be overwritten. + @type force: bool + @keyword neg_cone: A flag which if True will cause the negative cone to be added to the representation. + @type neg_cone: bool + """ + + # Monte Carlo simulation flag. + sim = False + num_sim = 0 + if hasattr(cdp, 'sim_number'): + sim = True + num_sim = cdp.sim_number + + # The inversion matrix. + inv_mat = -eye(3) + + # Create the structural object. + structure = Internal() + + # Create model for the positive and negative images. + model = structure.add_model(model=1) + if neg_cone: + model_neg = structure.add_model(model=2) + + # Create the molecule. + structure.add_molecule(name=cdp.model) + + # Alias the molecules. + mol = model.mol[0] + if neg_cone: + mol_neg = model_neg.mol[0] + + + # The pivot point. + ################## + + # Add the pivot point. + structure.add_atom(mol_name=cdp.model, pdb_record='HETATM', atom_num=1, atom_name='R', res_name='PIV', res_num=1, pos=cdp.pivot, element='C') + + + # The axes. + ########### + + # The spherical angles. + if cdp.model in ['iso cone', 'free rotor', 'iso cone, torsionless', 'iso cone, free rotor', 'rotor']: + # Print out. + print("\nGenerating the z-axis system.") + + # The axis. + axis = zeros(3, float64) + spherical_to_cartesian([1.0, getattr(cdp, 'axis_theta'), getattr(cdp, 'axis_phi')], axis) + print(("Central axis: %s." % axis)) + + # Rotations and inversions. + axis_pos = axis + axis_neg = dot(inv_mat, axis) + + # Simulation central axis. + axis_sim_pos = None + axis_sim_neg = None + if sim: + # Init. + axis_sim = zeros((cdp.sim_number, 3), float64) + + # Fill the structure. + for i in range(cdp.sim_number): + spherical_to_cartesian([1.0, getattr(cdp, 'axis_theta_sim')[i], getattr(cdp, 'axis_phi_sim')[i]], axis_sim[i]) + + # Inversion. + axis_sim_pos = axis_sim + axis_sim_neg = transpose(dot(inv_mat, transpose(axis_sim_pos))) + + # Generate the axis vectors. + print("\nGenerating the axis vectors.") + res_num = geometric.generate_vector_residues(mol=mol, vector=axis_pos, atom_name='z-ax', res_name_vect='AXE', sim_vectors=axis_sim_pos, res_num=2, origin=cdp.pivot, scale=size) + + # The negative. + if neg_cone: + res_num = geometric.generate_vector_residues(mol=mol_neg, vector=axis_neg, atom_name='z-ax', res_name_vect='AXE', sim_vectors=axis_sim_neg, res_num=2, origin=cdp.pivot, scale=size) + + # The full axis system. + else: + # Print out. + print("\nGenerating the full axis system.") + + # The axis system. + axes = zeros((3, 3), float64) + euler_to_R_zyz(cdp.eigen_alpha, cdp.eigen_beta, cdp.eigen_gamma, axes) + print(("Axis system:\n%s" % axes)) + + # Rotations and inversions. + axes_pos = axes + axes_neg = dot(inv_mat, axes) + + # Simulations + axes_sim_pos = None + axes_sim_neg = None + if sim: + # Init. + axes_sim_pos = zeros((cdp.sim_number, 3, 3), float64) + axes_sim_neg = zeros((cdp.sim_number, 3, 3), float64) + + # Fill the structure. + for i in range(cdp.sim_number): + # The positive system. + euler_to_R_zyz(cdp.eigen_alpha_sim[i], cdp.eigen_beta_sim[i], cdp.eigen_gamma_sim[i], axes_sim_pos[i]) + + # The negative system. + euler_to_R_zyz(cdp.eigen_alpha_sim[i], cdp.eigen_beta_sim[i], cdp.eigen_gamma_sim[i], axes_sim_neg[i]) + axes_sim_neg[i] = dot(inv_mat, axes_sim_neg[i]) + + # Generate the axis vectors. + print("\nGenerating the axis vectors.") + label = ['x', 'y', 'z'] + for j in range(len(label)): + # The simulation data. + axis_sim_pos = None + axis_sim_neg = None + if sim: + axis_sim_pos = axes_sim_pos[:,:, j] + axis_sim_neg = axes_sim_neg[:,:, j] + + # The vectors. + res_num = geometric.generate_vector_residues(mol=mol, vector=axes_pos[:, j], atom_name='%s-ax'%label[j], res_name_vect='AXE', sim_vectors=axis_sim_pos, res_num=2, origin=cdp.pivot, scale=size) + if neg_cone: + res_num = geometric.generate_vector_residues(mol=mol_neg, vector=axes_neg[:, j], atom_name='%s-ax'%label[j], res_name_vect='AXE', sim_vectors=axis_sim_neg, res_num=2, origin=cdp.pivot, scale=size) + + + # The cone object. + ################## + + # Skip models missing a cone. + if cdp.model not in ['rotor', 'free rotor']: + # The rotation matrix (rotation from the z-axis to the cone axis). + if cdp.model not in ['iso cone', 'iso cone, torsionless', 'iso cone, free rotor']: + R = axes + else: + R = zeros((3, 3), float64) + two_vect_to_R(array([0, 0, 1], float64), axis, R) + + # Average position rotation. + R_pos = R + R_neg = dot(inv_mat, R) + + # The pseudo-ellipse cone object. + if cdp.model in ['pseudo-ellipse', 'pseudo-ellipse, torsionless', 'pseudo-ellipse, free rotor']: + cone = Pseudo_elliptic(cdp.cone_theta_x, cdp.cone_theta_y) + + # The isotropic cone object. + else: + # The angle. + if hasattr(cdp, 'cone_theta'): + cone_theta = cdp.cone_theta + elif hasattr(cdp, 'cone_s1'): + cone_theta = order_parameters.iso_cone_S_to_theta(cdp.cone_s1) + + # The object. + cone = Iso_cone(cone_theta) + + # Create the positive and negative cones. + geometric.create_cone_pdb(mol=mol, cone=cone, start_res=mol.res_num[-1]+1, apex=cdp.pivot, R=R_pos, inc=inc, distribution='regular', axis_flag=False) + + # The negative. + if neg_cone: + geometric.create_cone_pdb(mol=mol_neg, cone=cone, start_res=mol_neg.res_num[-1]+1, apex=cdp.pivot, R=R_neg, inc=inc, distribution='regular', axis_flag=False) + + + # Create the PDB file. + ###################### + + # Print out. + print("\nGenerating the PDB file.") + + # Write the file. + pdb_file = open_write_file(file, dir, force=force) + structure.write_pdb(pdb_file) + pdb_file.close() + + def _pdb_model(self, ave_pos_file="ave_pos.pdb", rep_file="frame_order.pdb", dist_file="domain_distribution.pdb", dir=None, size=30.0, inc=36, force=False, neg_cone=True): - """Create a PDB file containing a geometric object representing the Frame Order cone models. - - @keyword ave_pos_file: The name of the file for the average molecule structure. + """Create 3 different PDB files for representing the frame order dynamics of the system. + + @keyword ave_pos_file: The name of the file for the average molecule structure. @type ave_pos_file: str @keyword rep_file: The name of the file of the PDB representation of the frame order dynamics to create. @type rep_file: str @@ -970,180 +1184,18 @@ # Test if the current data pipe exists. pipes.test() - # Negative cone flag. - neg_cone = True - - # Monte Carlo simulation flag. - sim = False - num_sim = 0 - if hasattr(cdp, 'sim_number'): - sim = True - num_sim = cdp.sim_number - - # The inversion matrix. - inv_mat = -eye(3) - - # Create the structural object. - structure = Internal() - - # Create model for the positive and negative images. - model = structure.add_model(model=1) - if neg_cone: - model_neg = structure.add_model(model=2) - - # Create the molecule. - structure.add_molecule(name=cdp.model) - - # Alias the molecules. - mol = model.mol[0] - if neg_cone: - mol_neg = model_neg.mol[0] - - - # The pivot point. - ################## - - # Add the pivot point. - structure.add_atom(mol_name=cdp.model, pdb_record='HETATM', atom_num=1, atom_name='R', res_name='PIV', res_num=1, pos=cdp.pivot, element='C') - - - # The axes. - ########### - - # The spherical angles. - if cdp.model in ['iso cone', 'free rotor', 'iso cone, torsionless', 'iso cone, free rotor', 'rotor']: - # Print out. - print("\nGenerating the z-axis system.") - - # The axis. - axis = zeros(3, float64) - spherical_to_cartesian([1.0, getattr(cdp, 'axis_theta'), getattr(cdp, 'axis_phi')], axis) - print(("Central axis: %s." % axis)) - - # Rotations and inversions. - axis_pos = axis - axis_neg = dot(inv_mat, axis) - - # Simulation central axis. - axis_sim_pos = None - axis_sim_neg = None - if sim: - # Init. - axis_sim = zeros((cdp.sim_number, 3), float64) - - # Fill the structure. - for i in range(cdp.sim_number): - spherical_to_cartesian([1.0, getattr(cdp, 'axis_theta_sim')[i], getattr(cdp, 'axis_phi_sim')[i]], axis_sim[i]) - - # Inversion. - axis_sim_pos = axis_sim - axis_sim_neg = transpose(dot(inv_mat, transpose(axis_sim_pos))) - - # Generate the axis vectors. - print("\nGenerating the axis vectors.") - res_num = geometric.generate_vector_residues(mol=mol, vector=axis_pos, atom_name='z-ax', res_name_vect='AXE', sim_vectors=axis_sim_pos, res_num=2, origin=cdp.pivot, scale=size) - - # The negative. - if neg_cone: - res_num = geometric.generate_vector_residues(mol=mol_neg, vector=axis_neg, atom_name='z-ax', res_name_vect='AXE', sim_vectors=axis_sim_neg, res_num=2, origin=cdp.pivot, scale=size) - - # The full axis system. - else: - # Print out. - print("\nGenerating the full axis system.") - - # The axis system. - axes = zeros((3, 3), float64) - euler_to_R_zyz(cdp.eigen_alpha, cdp.eigen_beta, cdp.eigen_gamma, axes) - print(("Axis system:\n%s" % axes)) - - # Rotations and inversions. - axes_pos = axes - axes_neg = dot(inv_mat, axes) - - # Simulations - axes_sim_pos = None - axes_sim_neg = None - if sim: - # Init. - axes_sim_pos = zeros((cdp.sim_number, 3, 3), float64) - axes_sim_neg = zeros((cdp.sim_number, 3, 3), float64) - - # Fill the structure. - for i in range(cdp.sim_number): - # The positive system. - euler_to_R_zyz(cdp.eigen_alpha_sim[i], cdp.eigen_beta_sim[i], cdp.eigen_gamma_sim[i], axes_sim_pos[i]) - - # The negative system. - euler_to_R_zyz(cdp.eigen_alpha_sim[i], cdp.eigen_beta_sim[i], cdp.eigen_gamma_sim[i], axes_sim_neg[i]) - axes_sim_neg[i] = dot(inv_mat, axes_sim_neg[i]) - - # Generate the axis vectors. - print("\nGenerating the axis vectors.") - label = ['x', 'y', 'z'] - for j in range(len(label)): - # The simulation data. - axis_sim_pos = None - axis_sim_neg = None - if sim: - axis_sim_pos = axes_sim_pos[:,:, j] - axis_sim_neg = axes_sim_neg[:,:, j] - - # The vectors. - res_num = geometric.generate_vector_residues(mol=mol, vector=axes_pos[:, j], atom_name='%s-ax'%label[j], res_name_vect='AXE', sim_vectors=axis_sim_pos, res_num=2, origin=cdp.pivot, scale=size) - if neg_cone: - res_num = geometric.generate_vector_residues(mol=mol_neg, vector=axes_neg[:, j], atom_name='%s-ax'%label[j], res_name_vect='AXE', sim_vectors=axis_sim_neg, res_num=2, origin=cdp.pivot, scale=size) - - - # The cone object. - ################## - - # Skip models missing a cone. - if cdp.model not in ['rotor', 'free rotor']: - # The rotation matrix (rotation from the z-axis to the cone axis). - if cdp.model not in ['iso cone', 'iso cone, torsionless', 'iso cone, free rotor']: - R = axes - else: - R = zeros((3, 3), float64) - two_vect_to_R(array([0, 0, 1], float64), axis, R) - - # Average position rotation. - R_pos = R - R_neg = dot(inv_mat, R) - - # The pseudo-ellipse cone object. - if cdp.model in ['pseudo-ellipse', 'pseudo-ellipse, torsionless', 'pseudo-ellipse, free rotor']: - cone = Pseudo_elliptic(cdp.cone_theta_x, cdp.cone_theta_y) - - # The isotropic cone object. - else: - # The angle. - if hasattr(cdp, 'cone_theta'): - cone_theta = cdp.cone_theta - elif hasattr(cdp, 'cone_s1'): - cone_theta = order_parameters.iso_cone_S_to_theta(cdp.cone_s1) - - # The object. - cone = Iso_cone(cone_theta) - - # Create the positive and negative cones. - geometric.create_cone_pdb(mol=mol, cone=cone, start_res=mol.res_num[-1]+1, apex=cdp.pivot, R=R_pos, inc=inc, distribution='regular', axis_flag=False) - - # The negative. - if neg_cone: - geometric.create_cone_pdb(mol=mol_neg, cone=cone, start_res=mol_neg.res_num[-1]+1, apex=cdp.pivot, R=R_neg, inc=inc, distribution='regular', axis_flag=False) - - - # Create the PDB file. - ###################### - - # Print out. - print("\nGenerating the PDB file.") - - # Write the file. - pdb_file = open_write_file(file, dir, force=force) - structure.write_pdb(pdb_file) - pdb_file.close() + # Create the average position structure. + self._pdb_ave_pos(file=ave_pos_file, dir=dir, force=force) + + # Nothing more to do for the rigid model. + if cdp.model == 'rigid': + return + + # Create the geometric representation. + self._pdb_geometric_rep(file=rep_file, dir=dir, size=size, inc=inc, force=force, neg_cone=neg_cone) + + # Create the distribution. + self._pdb_distribution(file=dist_file, dir=dir, force=force) def _pivot(self, pivot=None, fix=None):