Author: bugman Date: Mon Jul 16 18:26:42 2012 New Revision: 17257 URL: http://svn.gna.org/viewcvs/relax?rev=17257&view=rev Log: Merged revisions 17254-17255 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r17254 | bugman | 2012-07-16 12:02:30 +0200 (Mon, 16 Jul 2012) | 6 lines Bug fix for the RDC Q factor calculations for when the dipolar constants are not all the same. Now instead of a RelaxError, a warning is given and the Q factor normalised by 2Da^2(4 + 3R)/5 is skipped. This allows long range and mixed nuclear pairs to be supported. ........ r17255 | bugman | 2012-07-16 15:26:11 +0200 (Mon, 16 Jul 2012) | 5 lines Added the 'unit' argument to the dipole_pair.read_dist and dipole_pair.set_dist user functions. This is to allow distances in Angstroms to be read into relax and converted to meters. ........ Modified: branches/frame_order_testing/ (props changed) branches/frame_order_testing/generic_fns/dipole_pair.py branches/frame_order_testing/generic_fns/rdc.py branches/frame_order_testing/user_functions/dipole_pair.py Propchange: branches/frame_order_testing/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Mon Jul 16 18:26:42 2012 @@ -1,1 +1,1 @@ -/trunk:1-17249 +/trunk:1-17256 Modified: branches/frame_order_testing/generic_fns/dipole_pair.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/generic_fns/dipole_pair.py?rev=17257&r1=17256&r2=17257&view=diff ============================================================================== --- branches/frame_order_testing/generic_fns/dipole_pair.py (original) +++ branches/frame_order_testing/generic_fns/dipole_pair.py Mon Jul 16 18:26:42 2012 @@ -139,13 +139,15 @@ write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2"], data=ids) -def read_dist(file=None, dir=None, spin_id1_col=None, spin_id2_col=None, data_col=None, sep=None): +def read_dist(file=None, dir=None, unit='meter', spin_id1_col=None, spin_id2_col=None, data_col=None, sep=None): """Set up the magnetic dipole-dipole interaction. @keyword file: The name of the file to open. @type file: str @keyword dir: The directory containing the file (defaults to the current directory if None). @type dir: str or None + @keyword unit: The measurement unit. This can be either 'meter' or 'Angstrom'. + @type unit: str @keyword spin_id1_col: The column containing the spin ID strings of the first spin. @type spin_id1_col: int @keyword spin_id2_col: The column containing the spin ID strings of the second spin. @@ -156,6 +158,10 @@ @type sep: str or None """ + # Check the units. + if unit not in ['meter', 'Angstrom']: + raise RelaxError("The measurement unit of '%s' must be one of 'meter' or 'Angstrom'." % unit) + # Test if the current data pipe exists. pipes.test() @@ -195,6 +201,10 @@ warn(RelaxWarning("The averaged distance of '%s' from the line %s is invalid." % (ave_dist, line))) continue + # Unit conversion. + if unit == 'Angstrom': + ave_dist = ave_dist * 1e-10 + # Get the interatomic data container. interatom = return_interatom(spin_id1, spin_id2) @@ -214,10 +224,10 @@ # Print out. print("The following averaged distances have been read:\n") - write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", "Ave_distance"], data=data) - - -def set_dist(spin_id1=None, spin_id2=None, ave_dist=None): + write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", "Ave_distance(meters)"], data=data) + + +def set_dist(spin_id1=None, spin_id2=None, ave_dist=None, unit='meter'): """Set up the magnetic dipole-dipole interaction. @keyword spin_id1: The spin identifier string of the first spin of the pair. @@ -226,7 +236,17 @@ @type spin_id2: str @keyword ave_dist: The r^-3 averaged interatomic distance. @type ave_dist: float + @keyword unit: The measurement unit. This can be either 'meter' or 'Angstrom'. + @type unit: str """ + + # Check the units. + if unit not in ['meter', 'Angstrom']: + raise RelaxError("The measurement unit of '%s' must be one of 'meter' or 'Angstrom'." % unit) + + # Unit conversion. + if unit == 'Angstrom': + ave_dist = ave_dist * 1e-10 # Generate the selection objects. sel_obj1 = Selection(spin_id1) @@ -255,7 +275,7 @@ # Print out. print("The following averaged distances have been set:\n") - write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", "Ave_distance"], data=data) + write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", "Ave_distance(meters)"], data=data) def unit_vectors(ave=True): Modified: branches/frame_order_testing/generic_fns/rdc.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/generic_fns/rdc.py?rev=17257&r1=17256&r2=17257&view=diff ============================================================================== --- branches/frame_order_testing/generic_fns/rdc.py (original) +++ branches/frame_order_testing/generic_fns/rdc.py Mon Jul 16 18:26:42 2012 @@ -327,6 +327,7 @@ interatom_count = 0 rdc_data = False rdc_bc_data = False + norm2_flag = True for interatom in interatomic_loop(): # Increment the counter. interatom_count += 1 @@ -357,8 +358,9 @@ # Calculate the RDC dipolar constant (in Hertz, and the 3 comes from the alignment tensor), and append it to the list. dj_new = 3.0/(2.0*pi) * dipolar_constant(g1, g2, interatom.r) - if dj and dj_new != dj: - raise RelaxError("All the RDCs must come from the same nucleus type.") + if norm2_flag and dj != None and dj_new != dj: + warn(RelaxWarning("The dipolar constant is not the same for all RDCs, skipping the Q factor normalised with 2Da^2(4 + 3R)/5.")) + norm2_flag = False else: dj = dj_new @@ -377,20 +379,25 @@ return # Normalisation factor of 2Da^2(4 + 3R)/5. - D = dj * cdp.align_tensors[cdp.align_ids.index(align_id)].A_diag - Da = 1.0/3.0 * (D[2, 2] - (D[0, 0]+D[1, 1])/2.0) - Dr = 1.0/3.0 * (D[0, 0] - D[1, 1]) - if Da == 0: - R = nan + if norm2_flag: + D = dj * cdp.align_tensors[cdp.align_ids.index(align_id)].A_diag + Da = 1.0/3.0 * (D[2, 2] - (D[0, 0]+D[1, 1])/2.0) + Dr = 1.0/3.0 * (D[0, 0] - D[1, 1]) + if Da == 0: + R = nan + else: + R = Dr / Da + norm = 2.0 * (Da)**2 * (4.0 + 3.0*R**2)/5.0 + if Da == 0.0: + norm = 1e-15 + + # The Q-factor for the alignment. + cdp.q_factors_rdc[align_id] = sqrt(sse / N / norm) + else: - R = Dr / Da - norm = 2.0 * (Da)**2 * (4.0 + 3.0*R**2)/5.0 - if Da == 0.0: - norm = 1e-15 - - # The Q-factor for the alignment. - Q = sqrt(sse / N / norm) - cdp.q_factors_rdc[align_id] = Q + cdp.q_factors_rdc[align_id] = 0.0 + + # The second Q-factor definition. cdp.q_factors_rdc_norm2[align_id] = sqrt(sse / D2_sum) # The total Q-factor. Modified: branches/frame_order_testing/user_functions/dipole_pair.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/user_functions/dipole_pair.py?rev=17257&r1=17256&r2=17257&view=diff ============================================================================== --- branches/frame_order_testing/user_functions/dipole_pair.py (original) +++ branches/frame_order_testing/user_functions/dipole_pair.py Mon Jul 16 18:26:42 2012 @@ -106,6 +106,16 @@ can_be_none = True ) uf.add_keyarg( + name = "unit", + default = "meter", + py_type = "str", + desc_short = "distance unit", + desc = "The unit of distance (the default is 'meter').", + wiz_element_type = "combo", + wiz_combo_choices = ["meter", "Angstrom"], + wiz_read_only = True +) +uf.add_keyarg( name = "spin_id1_col", default = 1, py_type = "int", @@ -142,13 +152,13 @@ ) # Description. uf.desc.append(Desc_container()) -uf.desc[-1].add_paragraph("As the magnetic dipole-dipole interaction is averaged in NMR over the interatomic distance to the inverse third power, the interatomic distances within a 3D structural file are of no use for defining the interaction. Therefore these average distances must be explicitly defined.") +uf.desc[-1].add_paragraph("As the magnetic dipole-dipole interaction is averaged in NMR over the interatomic distance to the inverse third power, the interatomic distances within a 3D structural file are of no use for defining the interaction. Therefore these average distances must be explicitly defined. The default measurement unit is 'meter' but this can be changed to 'Angstrom'.") uf.desc[-1].add_paragraph("This user function allows these r^-3 averaged interatomic distances to be read from a file. This is useful in the case when the dipole-dipole distances vary, replacing the need to call the dipole_pair.set_dist user function many times. The format of the file should be columnar, with the two spin ID strings in two separate columns and the averaged distances in any other.") # Prompt examples. uf.desc.append(Desc_container("Prompt examples")) -uf.desc[-1].add_paragraph("To load the distances from the fifth column of the 'distances' file, and where the spin IDs are in the first and second columns, type one of the following:") +uf.desc[-1].add_paragraph("To load the distances in meters from the fifth column of the 'distances' file, and where the spin IDs are in the first and second columns, type one of the following:") uf.desc[-1].add_prompt("relax> dipole_pair.read_dist('distances', 1, 2, 5)") -uf.desc[-1].add_prompt("relax> dipole_pair.read_dist(file='distances', spin_id1_col=1, spin_id2_col=2, data_col=5)") +uf.desc[-1].add_prompt("relax> dipole_pair.read_dist(file='distances', unit='meter', spin_id1_col=1, spin_id2_col=2, data_col=5)") uf.backend = dipole_pair.read_dist uf.menu_text = "&read_dist" uf.gui_icon = "oxygen.actions.document-open" @@ -181,17 +191,28 @@ name = "ave_dist", default = NH_BOND_LENGTH, py_type = "float", - desc_short = "averaged interatomic distance (meters)", - desc = "The r^-3 averaged distance between the two spins to be used in the magnetic dipole constant." -) -# Description. -uf.desc.append(Desc_container()) -uf.desc[-1].add_paragraph("As the magnetic dipole-dipole interaction is averaged in NMR over the interatomic distance to the inverse third power, the interatomic distances within a 3D structural file are of no use for defining the interaction. Therefore these average distances must be explicitly supplied. This user function allows these distances to be set up.") + desc_short = "averaged interatomic distance", + desc = "The r^-3 averaged distance between the two spins to be used in the magnetic dipole constant, defaulting to meters." +) +uf.add_keyarg( + name = "unit", + default = "meter", + py_type = "str", + desc_short = "distance unit", + desc = "The unit of distance (the default is 'meter').", + wiz_element_type = "combo", + wiz_combo_choices = ["meter", "Angstrom"], + wiz_read_only = True +) +# Description. +uf.desc.append(Desc_container()) +uf.desc[-1].add_paragraph("As the magnetic dipole-dipole interaction is averaged in NMR over the interatomic distance to the inverse third power, the interatomic distances within a 3D structural file are of no use for defining the interaction. Therefore these average distances must be explicitly supplied. This user function allows these distances to be set up. The default measurement unit is 'meter' but this can be changed to 'Angstrom'.") # Prompt examples. uf.desc.append(Desc_container("Prompt examples")) uf.desc[-1].add_paragraph("To set the N-H distance for protein the 15N heteronuclear relaxation mechanism to 1.02 Angstrom, type one of the following:") uf.desc[-1].add_prompt("relax> dipole_pair.set_dist('@N', '@H', 1.02 * 1e-10)") -uf.desc[-1].add_prompt("relax> dipole_pair.set_dist(spin_id1='@N', spin_id2='@H', ave_dist=1.02 * 1e-10)") +uf.desc[-1].add_prompt("relax> dipole_pair.set_dist(spin_id1='@N', spin_id2='@H', ave_dist=1.02 * 1e-10, unit='meter')") +uf.desc[-1].add_prompt("relax> dipole_pair.set_dist(spin_id1='@N', spin_id2='@H', ave_dist=1.02, unit='Angstrom')") uf.backend = dipole_pair.set_dist uf.menu_text = "&set_dist" uf.gui_icon = "oxygen.actions.edit-rename"