Author: han87 Date: Tue Jun 28 10:25:55 2011 New Revision: 13249 URL: http://svn.gna.org/viewcvs/relax?rev=13249&view=rev Log: Reverted r13246 as different approach will be used. The command used was: svn merge -r 13246:13239 . The new function vectors_xyz() in the /prompt/structure.py is not needed. The current code will be fixed for xyz file format suggested in https://mail.gna.org/public/relax-devel/2011-06/msg00244.html. Modified: branches/xyz/generic_fns/structure/main.py branches/xyz/prompt/structure.py branches/xyz/test_suite/system_tests/structure.py Modified: branches/xyz/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/branches/xyz/generic_fns/structure/main.py?rev=13249&r1=13248&r2=13249&view=diff ============================================================================== --- branches/xyz/generic_fns/structure/main.py (original) +++ branches/xyz/generic_fns/structure/main.py Tue Jun 28 10:25:55 2011 @@ -609,6 +609,140 @@ raise RelaxError("No vectors could be extracted.") +def vectors_xyz(spin_id1=None, spin_id2=None, model=None, verbosity=1, ave=True, unit=True): + """Extract the bond vectors from the loaded structures and store them in the spin container. + + @keyword attached: The spin identifier string of the atom 1. + @type attached: str + @keyword spin_id: The spin identifier string of the atom 2. + @type spin_id: str + @keyword model: The model to extract the vector from. If None, all vectors will be + extracted. + @type model: str + @keyword verbosity: The higher the value, the more information is printed to screen. + @type verbosity: int + @keyword ave: A flag which if True will cause the average of all vectors to be + extracted. + @type ave: bool + @keyword unit: A flag which if True will cause the function to calculate the unit + vectors. + @type unit: bool + """ + + # Test if the PDB file has been loaded. + if not hasattr(cdp, 'structure'): + raise RelaxPdbError + + # Test if sequence data is loaded. + if not exists_mol_res_spin_data(): + raise RelaxNoSequenceError + + # Print out. + if verbosity: + # Number of models. + num_models = cdp.structure.num_models() + + # Multiple models loaded. + if num_models > 1: + if model: + print(("Extracting vectors for model '%s'." % model)) + else: + print(("Extracting vectors for all %s models." % num_models)) + if ave: + print("Averaging all vectors.") + + # Single model loaded. + else: + print("Extracting vectors from the single model.") + + # Unit vectors. + if unit: + print("Calculating the unit vectors.") + + # Loop over the spins. + no_vectors = True + for spin1, mol_name1, res_num1, res_name1 in spin_loop(selection=spin_id1, full_info=True): + # Skip deselected spins. + if not spin.select: + continue + + # The spin identification string. The residue name and spin num is not included to allow molecules with point mutations to be used as different models. + id1 = generate_spin_id(res_num1=res_num1, res_name1=None, spin_num1=res_num1) + + # Test that the spin number or name are set (one or both are essential for the identification of the atom). + if spin.num == None and spin.name == None: + warn(RelaxWarning("Either the spin number or name must be set for the spin " + repr(id) + " to identify the corresponding atom in the molecule.")) + continue + + # The bond vector already exists. + if hasattr(spin, object_name): + obj = getattr(spin, object_name) + if obj: + warn(RelaxWarning("The bond vector for the spin " + repr(id) + " already exists.")) + continue + + # Get the bond info. + bond_vectors, attached_name, warnings = cdp.structure.bond_vectors(attached_atom=attached, model_num=model, res_num=res_num, spin_name=spin.name, return_name=True, return_warnings=True) + + # No attached atom. + if not bond_vectors: + # Warning messages. + if warnings: + warn(RelaxWarning(warnings + " (atom ID " + repr(id) + ").")) + + # Skip the spin. + continue + + # Set the attached atom name. + if not hasattr(spin, 'attached_atom'): + spin.attached_atom = attached_name + elif spin.attached_atom != attached_name: + raise RelaxError("The " + repr(spin.attached_atom) + " atom already attached to the spin does not match the attached atom " + repr(attached_name) + ".") + + # Initialise the average vector. + if ave: + ave_vector = zeros(3, float64) + + # Loop over the individual vectors. + for i in xrange(len(bond_vectors)): + # Unit vector. + if unit: + # Normalisation factor. + norm_factor = norm(bond_vectors[i]) + + # Test for zero length. + if norm_factor == 0.0: + warn(RelaxZeroVectorWarning(id)) + + # Calculate the normalised vector. + else: + bond_vectors[i] = bond_vectors[i] / norm_factor + + # Sum the vectors. + if ave: + ave_vector = ave_vector + bond_vectors[i] + + # Average. + if ave: + vector = ave_vector / float(len(bond_vectors)) + else: + vector = bond_vectors + + # Set the vector. + setattr(spin, object_name, vector) + + # We have a vector! + no_vectors = False + + # Print out of modified spins. + if verbosity: + print(("Extracted " + spin.name + "-" + attached_name + " vectors for " + repr(id) + '.')) + + # Right, catch the problem of missing vectors to prevent massive user confusion! + if no_vectors: + raise RelaxError("No vectors could be extracted.") + + def write_pdb(file=None, dir=None, model_num=None, force=False): """The PDB writing function. Modified: branches/xyz/prompt/structure.py URL: http://svn.gna.org/viewcvs/relax/branches/xyz/prompt/structure.py?rev=13249&r1=13248&r2=13249&view=diff ============================================================================== --- branches/xyz/prompt/structure.py (original) +++ branches/xyz/prompt/structure.py Tue Jun 28 10:25:55 2011 @@ -686,76 +686,6 @@ generic_fns.structure.main.vectors(attached=attached, spin_id=spin_id, model=model, verbosity=verbosity, ave=ave, unit=unit) - def vectors_xyz(self, spin_id1=None, spin_id2=None, model=None, verbosity=1, ave=True, unit=True): - """Extract and store the bond vectors from the loaded structures in the spin container. - - Keyword arguments - ~~~~~~~~~~~~~~~~~ - - spin_id1: The spin identification string of the spin 1. - - spin_id2: The spin identification string of the spin 2. - - model: The model to extract bond vectors from (which if set to None will cause the vectors - of all models to be extracted). - - verbosity: The amount of information to print to screen. Zero corresponds to minimal - output while higher values increase the amount of output. The default value is 1. - - ave: A flag which if True will cause the bond vectors from all models to be averaged. If - vectors from only one model is extracted, this argument will have no effect. - - unit: A flag which if True will cause the unit vector to calculated rather than the full - length bond vector. - - - Description - ~~~~~~~~~~~ - - For a number of types of analysis, bond vectors or unit bond vectors are required for the - calculations. This user function allows these vectors to be extracted from the loaded - structures. The bond vector will be that from the two atoms of a xyz file loaded in relax. - - The extraction of vectors can occur in a number of ways. For example if an NMR structure - with N models is loaded or if multiple molecules, from any source, of the same compound are - loaded as different models, there are three options for extracting the bond vector. Firstly - the bond vector of a single model can be extracted by setting the 'model' argument. - Secondly the bond vectors from all models can be extracted if 'model' is None and 'ave' is - set to False. Thirdly, if 'model' is None and 'ave' is set to True, then a single vector - which is the average for all models will be calculated. - - - Example - ~~~~~~~ - - To extract a vector of two atoms from xyz file, type: - - relax> structure.vectors(spin_id1='#SSS-cluster4-new-test_mol1@2', spin_id1='#SSS-cluster4-new-test_mol1@1') - """ - - # Function intro text. - if self._exec_info.intro: - text = self._exec_info.ps3 + "structure.vectors(" - text = text + "spin_id1=" + repr(spin_id1) - text = text + ", spin_id2=" + repr(spin_id2) - text = text + ", model=" + repr(model) - text = text + ", verbosity=" + repr(verbosity) - text = text + ", ave=" + repr(ave) - text = text + ", unit=" + repr(unit) + ")" - print(text) - - # The argument checks. - arg_check.is_str(spin_id1, 'spin_identification_string', can_be_none=True) - arg_check.is_str(spin_id2, 'spin identification string', can_be_none=True) - arg_check.is_int(model, 'model', can_be_none=True) - arg_check.is_int(verbosity, 'verbosity level') - arg_check.is_bool(ave, 'average vector flag') - arg_check.is_bool(unit, 'unit vector flag') - - # Execute the functional code. - generic_fns.structure.main.vectors_xyz(spin_id1=spin_id1, spin_id2=spin_id2, model=model, verbosity=verbosity, ave=ave, unit=unit) - - def write_pdb(self, file=None, dir=None, model_num=None, force=False): """The PDB writing function. Modified: branches/xyz/test_suite/system_tests/structure.py URL: http://svn.gna.org/viewcvs/relax/branches/xyz/test_suite/system_tests/structure.py?rev=13249&r1=13248&r2=13249&view=diff ============================================================================== --- branches/xyz/test_suite/system_tests/structure.py (original) +++ branches/xyz/test_suite/system_tests/structure.py Tue Jun 28 10:25:55 2011 @@ -685,7 +685,3 @@ # And now all the rest of the atoms. self.interpreter.structure.load_spins() - # Extract a vector between first two spins. - self.interpreter.structure.vectors_xyz(spin_id1='#SSS-cluster4-new-test_mol1@1', spin_id2='#SSS-cluster4-new-test_mol1@2') - print((cdp.mol[0].res[0].spin[0])) - self.assert_(hasattr(cdp.mol[0].res[0].spin[0], 'bond_vect'))