Пример #1
0
def write_param_files(global_file=None, kex=1500.0, pA=0.95, set_file=None, dir=None, r1=False, force=False):
    """Create the CATIA parameter files.

    @keyword global_file:   The name of the global parameter file.
    @type global_file:      str
    @keyword set_file:      The name of the parameter set file.
    @type set_file:         str
    @keyword dir:           The base directory to place the files into.
    @type dir:              str
    @keyword r1:            A flag which if True will cause the R1 data to be used for off-resonance effects.
    @type r1:               bool
    @keyword force:         A flag which if True will cause a pre-existing file to be overwritten.
    @type force:            bool
    """

    # Open the global parameter file.
    param_file = open_write_file(file_name=global_file, dir=dir, force=force)

    # Set the starting values.
    param_file.write("kex = %s\n" % kex)
    param_file.write("pb = %s\n" % (1.0-pA))

    # Close the file.
    param_file.close()

    # Open the 1st parameter set file.
    set_file = open_write_file(file_name=set_file, dir=dir, force=force)

    # The parameter format.
    params = ['Delta0']
    values = [0.5]
    if r1:
        for frq in loop_frq():
            params.append("R1iph_%s" % frq_label(frq))
            values.append(1.5)
    for frq in loop_frq():
        params.append("R0iph_%s" % frq_label(frq))
        values.append(5.0)
    if r1:
        params.append("Omega")
        values.append(0.0)

    # Write out the format.
    set_file.write("format = (")
    for i in range(len(params)):
        if i != 0:
            set_file.write(';')
        set_file.write(params[i])
    set_file.write(")\n")

    # Um?!?  The average values maybe?
    set_file.write("* = (")
    for i in range(len(values)):
        if i != 0:
            set_file.write(';')
        set_file.write("%s" % values[i])
    set_file.write(")\n")

    # Close the file.
    set_file.close()
Пример #2
0
def back_calc_r2eff(spins=None, spin_ids=None, cpmg_frqs=None, spin_lock_offset=None, spin_lock_nu1=None, relax_times_new=None, store_chi2=False):
    """Back-calculation of R2eff/R1rho values for the given spin.

    @keyword spins:             The list of specific spin data container for cluster.
    @type spins:                List of SpinContainer instances
    @keyword spin_ids:          The list of spin ID strings for the spin containers in cluster.
    @type spin_ids:             list of str
    @keyword cpmg_frqs:         The CPMG frequencies to use instead of the user loaded values - to enable interpolation.
    @type cpmg_frqs:            list of lists of numpy rank-1 float arrays
    @keyword spin_lock_offset:  The spin-lock offsets to use instead of the user loaded values - to enable interpolation.
    @type spin_lock_offset:     list of lists of numpy rank-1 float arrays
    @keyword spin_lock_nu1:     The spin-lock field strengths to use instead of the user loaded values - to enable interpolation.
    @type spin_lock_nu1:        list of lists of numpy rank-1 float arrays
    @keyword relax_times_new:   The interpolated experiment specific fixed time period for relaxation (in seconds).  The dimensions are {Ei, Mi, Oi, Di, Ti}.
    @type relax_times_new:      rank-4 list of floats
    @keyword store_chi2:        A flag which if True will cause the spin specific chi-squared value to be stored in the spin container.
    @type store_chi2:           bool
    @return:                    The back-calculated R2eff/R1rho value for the given spin.
    @rtype:                     numpy rank-1 float array
    """

    # Create the initial parameter vector.
    param_vector = assemble_param_vector(spins=spins)

    # Number of spectrometer fields.
    fields = [None]
    field_count = 1
    if hasattr(cdp, 'spectrometer_frq_count'):
        fields = cdp.spectrometer_frq_list
        field_count = cdp.spectrometer_frq_count

    # Initialise the data structures for the target function.
    values, errors, missing, frqs, frqs_H, exp_types, relax_times = return_r2eff_arrays(spins=spins, spin_ids=spin_ids, fields=fields, field_count=field_count)

    # The offset and R1 data.
    r1_setup()
    offsets, spin_lock_fields_inter, chemical_shifts, tilt_angles, Delta_omega, w_eff = return_offset_data(spins=spins, spin_ids=spin_ids, field_count=field_count, spin_lock_offset=spin_lock_offset, fields=spin_lock_nu1)
    r1 = return_r1_data(spins=spins, spin_ids=spin_ids, field_count=field_count)
    r1_fit = is_r1_optimised(spins[0].model)

    # The relaxation times.
    if relax_times_new != None:
        relax_times = relax_times_new

    # The dispersion data.
    recalc_tau = True
    if cpmg_frqs == None and spin_lock_nu1 == None and spin_lock_offset == None:
        cpmg_frqs = return_cpmg_frqs(ref_flag=False)
        spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)

    # Reset the cpmg_frqs if interpolating R1rho models.
    elif cpmg_frqs == None and spin_lock_offset != None:
        cpmg_frqs = None
        spin_lock_nu1 = spin_lock_fields_inter

        recalc_tau = False
        values = []
        errors = []
        missing = []
        for exp_type, ei in loop_exp(return_indices=True):
            values.append([])
            errors.append([])
            missing.append([])
            for si in range(len(spins)):
                values[ei].append([])
                errors[ei].append([])
                missing[ei].append([])
                for frq, mi in loop_frq(return_indices=True):
                    values[ei][si].append([])
                    errors[ei][si].append([])
                    missing[ei][si].append([])
                    for oi, offset in enumerate(offsets[ei][si][mi]):
                        num = len(spin_lock_nu1[ei][mi][oi])

                        values[ei][si][mi].append(zeros(num, float64))
                        errors[ei][si][mi].append(ones(num, float64))
                        missing[ei][si][mi].append(zeros(num, int32))

    # Reconstruct the structures for interpolation.
    else:
        recalc_tau = False
        values = []
        errors = []
        missing = []
        for exp_type, ei in loop_exp(return_indices=True):
            values.append([])
            errors.append([])
            missing.append([])
            for si in range(len(spins)):
                values[ei].append([])
                errors[ei].append([])
                missing[ei].append([])
                for frq, mi in loop_frq(return_indices=True):
                    values[ei][si].append([])
                    errors[ei][si].append([])
                    missing[ei][si].append([])
                    for offset, oi in loop_offset(exp_type=exp_type, frq=frq, return_indices=True):
                        if exp_type in EXP_TYPE_LIST_CPMG:
                            num = len(cpmg_frqs[ei][mi][oi])
                        else:
                            num = len(spin_lock_nu1[ei][mi][oi])
                        values[ei][si][mi].append(zeros(num, float64))
                        errors[ei][si][mi].append(ones(num, float64))
                        missing[ei][si][mi].append(zeros(num, int32))

    # Initialise the relaxation dispersion fit functions.
    model = Dispersion(model=spins[0].model, num_params=param_num(spins=spins), num_spins=len(spins), num_frq=field_count, exp_types=exp_types, values=values, errors=errors, missing=missing, frqs=frqs, frqs_H=frqs_H, cpmg_frqs=cpmg_frqs, spin_lock_nu1=spin_lock_nu1, chemical_shifts=chemical_shifts, offset=offsets, tilt_angles=tilt_angles, r1=r1, relax_times=relax_times, recalc_tau=recalc_tau, r1_fit=r1_fit)

    # Make a single function call.  This will cause back calculation and the data will be stored in the class instance.
    chi2 = model.func(param_vector)

    # Store the chi-squared value.
    if store_chi2:
        for spin in spins:
            spin.chi2 = chi2

    # Return the structure.
    return model.get_back_calc()
Пример #3
0
def back_calc_r2eff(spins=None, spin_ids=None, cpmg_frqs=None, spin_lock_offset=None, spin_lock_nu1=None, relax_times_new=None, store_chi2=False):
    """Back-calculation of R2eff/R1rho values for the given spin.

    @keyword spins:             The list of specific spin data container for cluster.
    @type spins:                List of SpinContainer instances
    @keyword spin_ids:          The list of spin ID strings for the spin containers in cluster.
    @type spin_ids:             list of str
    @keyword cpmg_frqs:         The CPMG frequencies to use instead of the user loaded values - to enable interpolation.
    @type cpmg_frqs:            list of lists of numpy rank-1 float arrays
    @keyword spin_lock_offset:  The spin-lock offsets to use instead of the user loaded values - to enable interpolation.
    @type spin_lock_offset:     list of lists of numpy rank-1 float arrays
    @keyword spin_lock_nu1:     The spin-lock field strengths to use instead of the user loaded values - to enable interpolation.
    @type spin_lock_nu1:        list of lists of numpy rank-1 float arrays
    @keyword relax_times_new:   The interpolated experiment specific fixed time period for relaxation (in seconds).  The dimensions are {Ei, Mi, Oi, Di, Ti}.
    @type relax_times_new:      rank-4 list of floats
    @keyword store_chi2:        A flag which if True will cause the spin specific chi-squared value to be stored in the spin container.
    @type store_chi2:           bool
    @return:                    The back-calculated R2eff/R1rho value for the given spin.
    @rtype:                     numpy rank-1 float array
    """

    # Create the initial parameter vector.
    param_vector = assemble_param_vector(spins=spins)

    # Number of spectrometer fields.
    fields = [None]
    field_count = 1
    if hasattr(cdp, 'spectrometer_frq_count'):
        fields = cdp.spectrometer_frq_list
        field_count = cdp.spectrometer_frq_count

    # Initialise the data structures for the target function.
    values, errors, missing, frqs, frqs_H, exp_types, relax_times = return_r2eff_arrays(spins=spins, spin_ids=spin_ids, fields=fields, field_count=field_count)

    # The offset and R1 data.
    r1_setup()
    offsets, spin_lock_fields_inter, chemical_shifts, tilt_angles, Delta_omega, w_eff = return_offset_data(spins=spins, spin_ids=spin_ids, field_count=field_count, spin_lock_offset=spin_lock_offset, fields=spin_lock_nu1)
    r1 = return_r1_data(spins=spins, spin_ids=spin_ids, field_count=field_count)
    r1_fit = is_r1_optimised(spins[0].model)

    # The relaxation times.
    if relax_times_new != None:
        relax_times = relax_times_new

    # The dispersion data.
    recalc_tau = True
    if cpmg_frqs == None and spin_lock_nu1 == None and spin_lock_offset == None:
        cpmg_frqs = return_cpmg_frqs(ref_flag=False)
        spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)

    # Reset the cpmg_frqs if interpolating R1rho models.
    elif cpmg_frqs == None and spin_lock_offset != None:
        cpmg_frqs = None
        spin_lock_nu1 = spin_lock_fields_inter

        recalc_tau = False
        values = []
        errors = []
        missing = []
        for exp_type, ei in loop_exp(return_indices=True):
            values.append([])
            errors.append([])
            missing.append([])
            for si in range(len(spins)):
                values[ei].append([])
                errors[ei].append([])
                missing[ei].append([])
                for frq, mi in loop_frq(return_indices=True):
                    values[ei][si].append([])
                    errors[ei][si].append([])
                    missing[ei][si].append([])
                    for oi, offset in enumerate(offsets[ei][si][mi]):
                        num = len(spin_lock_nu1[ei][mi][oi])

                        values[ei][si][mi].append(zeros(num, float64))
                        errors[ei][si][mi].append(ones(num, float64))
                        missing[ei][si][mi].append(zeros(num, int32))

    # Reconstruct the structures for interpolation.
    else:
        recalc_tau = False
        values = []
        errors = []
        missing = []
        for exp_type, ei in loop_exp(return_indices=True):
            values.append([])
            errors.append([])
            missing.append([])
            for si in range(len(spins)):
                values[ei].append([])
                errors[ei].append([])
                missing[ei].append([])
                for frq, mi in loop_frq(return_indices=True):
                    values[ei][si].append([])
                    errors[ei][si].append([])
                    missing[ei][si].append([])
                    for offset, oi in loop_offset(exp_type=exp_type, frq=frq, return_indices=True):
                        if exp_type in EXP_TYPE_LIST_CPMG:
                            num = len(cpmg_frqs[ei][mi][oi])
                        else:
                            num = len(spin_lock_nu1[ei][mi][oi])
                        values[ei][si][mi].append(zeros(num, float64))
                        errors[ei][si][mi].append(ones(num, float64))
                        missing[ei][si][mi].append(zeros(num, int32))

    # Initialise the relaxation dispersion fit functions.
    model = Dispersion(model=spins[0].model, num_params=param_num(spins=spins), num_spins=len(spins), num_frq=field_count, exp_types=exp_types, values=values, errors=errors, missing=missing, frqs=frqs, frqs_H=frqs_H, cpmg_frqs=cpmg_frqs, spin_lock_nu1=spin_lock_nu1, chemical_shifts=chemical_shifts, offset=offsets, tilt_angles=tilt_angles, r1=r1, relax_times=relax_times, recalc_tau=recalc_tau, r1_fit=r1_fit)

    # Make a single function call.  This will cause back calculation and the data will be stored in the class instance.
    chi2 = model.func(param_vector)

    # Store the chi-squared value.
    if store_chi2:
        for spin in spins:
            spin.chi2 = chi2

    # Return the structure.
    return model.get_back_calc()
Пример #4
0
def write_r2eff_files(input_dir=None, base_dir=None, force=False):
    """Create the CATIA R2eff input files.

    @keyword input_dir: The special directory for the R2eff input files.
    @type input_dir:    str
    @keyword base_dir:  The base directory to place the files into.
    @type base_dir:     str
    @keyword force:     A flag which if True will cause a pre-existing file to be overwritten.
    @type force:        bool
    """

    # Create the directory for the R2eff files for each field and spin.
    dir = base_dir + sep + input_dir
    mkdir_nofail(dir, verbosity=0)

    # Determine the isotope information.
    isotope = None
    for spin in spin_loop(skip_desel=True):
        if hasattr(spin, 'isotope'):
            if isotope == None:
                isotope = spin.isotope
            elif spin.isotope != isotope:
                raise RelaxError("CATIA only supports one spin type.")
    if isotope == None:
        raise RelaxError("The spin isotopes have not been specified.")

    # Isotope translation.
    if isotope == '1H':
        isotope = 'H1'
    elif isotope == '13C':
        isotope = 'C13'
    elif isotope == '15N':
        isotope = 'N15'

    # Loop over the frequencies.
    for frq, mi in loop_frq(return_indices=True):
        # The frequency string in MHz.
        frq_string = int(frq * 1e-6)

        # The set files.
        file_name = "data_set_%i.inp" % frq_string
        set_file = open_write_file(file_name=file_name,
                                   dir=base_dir,
                                   force=force)
        id = frq_string
        set_file.write("ID=%s\n" % id)
        set_file.write("Sfrq = %s\n" % frq_string)
        set_file.write("Temperature = %s\n" % 0.0)
        set_file.write("Nucleus = %s\n" % isotope)
        set_file.write("Couplednucleus = %s\n" % 'H1')
        set_file.write("Time_equil = %s\n" % 0.0)
        set_file.write("Pwx_cp = %s\n" % 0.0)
        set_file.write("Taub = %s\n" % 0.0)
        set_file.write("Time_T2 = %s\n" % cdp.relax_time_list[0])
        set_file.write("Xcar = %s\n" % 0.0)
        set_file.write("Seqfil = %s\n" % 'CW_CPMG')
        set_file.write("Minerror = %s\n" % "(2.%;0.5/s)")
        set_file.write("Basis = (%s)\n" % "Iph_7")
        set_file.write("Format = (%i;%i;%i)\n" % (0, 1, 2))
        set_file.write("DataDirectory = %s\n" % (dir + sep))
        set_file.write("Data = (\n")

        # Loop over the spins.
        for spin, mol_name, res_num, res_name, spin_id in spin_loop(
                full_info=True, return_id=True, skip_desel=True):
            # The file.
            file_name = "spin%s_%i.cpmg" % (spin_id.replace('#', '_').replace(
                ':', '_').replace('@', '_'), frq_string)
            spin_file = open_write_file(file_name=file_name,
                                        dir=dir,
                                        force=force)

            # Write the header.
            spin_file.write("# %18s %20s %20s\n" %
                            ("nu_cpmg(Hz)", "R2(1/s)", "Esd(R2)"))

            # Loop over the dispersion points.
            for offset, point, oi, di in loop_offset_point(
                    exp_type=EXP_TYPE_CPMG_SQ, frq=frq, return_indices=True):
                # The key.
                key = return_param_key_from_data(exp_type=EXP_TYPE_CPMG_SQ,
                                                 frq=frq,
                                                 offset=offset,
                                                 point=point)

                # No data.
                if key not in spin.r2eff:
                    continue

                # Write out the data.
                spin_file.write("%20.15f %20.15f %20.15f\n" %
                                (point, spin.r2eff[key], spin.r2eff_err[key]))

            # Close the file.
            spin_file.close()

            # Add the file name to the set.
            catia_spin_id = "%i%s" % (res_num, spin.name)
            set_file.write(" [%s;%s];\n" % (catia_spin_id, file_name))

        # Terminate the set file.
        set_file.write(")\n")
        set_file.close()
Пример #5
0
def write_param_files(global_file=None,
                      kex=1500.0,
                      pA=0.95,
                      set_file=None,
                      dir=None,
                      r1=False,
                      force=False):
    """Create the CATIA parameter files.

    @keyword global_file:   The name of the global parameter file.
    @type global_file:      str
    @keyword set_file:      The name of the parameter set file.
    @type set_file:         str
    @keyword dir:           The base directory to place the files into.
    @type dir:              str
    @keyword r1:            A flag which if True will cause the R1 data to be used for off-resonance effects.
    @type r1:               bool
    @keyword force:         A flag which if True will cause a pre-existing file to be overwritten.
    @type force:            bool
    """

    # Open the global parameter file.
    param_file = open_write_file(file_name=global_file, dir=dir, force=force)

    # Set the starting values.
    param_file.write("kex = %s\n" % kex)
    param_file.write("pb = %s\n" % (1.0 - pA))

    # Close the file.
    param_file.close()

    # Open the 1st parameter set file.
    set_file = open_write_file(file_name=set_file, dir=dir, force=force)

    # The parameter format.
    params = ['Delta0']
    values = [0.5]
    if r1:
        for frq in loop_frq():
            params.append("R1iph_%s" % frq_label(frq))
            values.append(1.5)
    for frq in loop_frq():
        params.append("R0iph_%s" % frq_label(frq))
        values.append(5.0)
    if r1:
        params.append("Omega")
        values.append(0.0)

    # Write out the format.
    set_file.write("format = (")
    for i in range(len(params)):
        if i != 0:
            set_file.write(';')
        set_file.write(params[i])
    set_file.write(")\n")

    # Um?!?  The average values maybe?
    set_file.write("* = (")
    for i in range(len(values)):
        if i != 0:
            set_file.write(';')
        set_file.write("%s" % values[i])
    set_file.write(")\n")

    # Close the file.
    set_file.close()
Пример #6
0
def write_main_file(file=None,
                    dir=None,
                    output_dir=None,
                    f_tol=1e-25,
                    max_iter=10000000,
                    r1=False,
                    force=False):
    """Create the main CATIA execution file.

    @keyword file:          The main CATIA execution file.
    @type file:             str
    @keyword dir:           The directory to place the files into.
    @type dir:              str or None
    @keyword output_dir:    The CATIA output directory, located within the directory specified by the dir argument.  This directory will be created.
    @type output_dir:       str
    @keyword r1:            A flag which if True will cause the R1 data to be used for off-resonance effects.
    @type r1:               bool
    @keyword force:         A flag which if True will cause a pre-existing file to be overwritten.
    @type force:            bool
    """

    # The file.
    catia_in = open_write_file(file_name=file, dir=dir, force=force)

    # The R2eff input sets.
    for frq in loop_frq():
        frq_label = int(frq * 1e-6)
        file_name = "data_set_%i.inp" % frq_label
        catia_in.write("ReadDataset(%s)\n" % file_name)

    # Write out the data.
    catia_in.write("ReadParam_Global(ParamGlobal.inp)\n")
    catia_in.write("ReadParam_Local(ParamSet1.inp)\n")
    catia_in.write("\n")

    # The R1 data for off-resonance effects.
    if r1:
        catia_in.write("ReadParam(Omega;%s;0;1)\n" % shift_file)
        for frq in loop_frq():
            frq_label = int(frq * 1e-6)
            param = "R1iph_%s" % frq_label
            r1_file = "R1_%s.out" % frq_label
            catia_in.write("ReadParam(%s;%s;0;1)\n" % (param, r1_file))
        catia_in.write("\n")

    # Fix these off-resonance parameters.
    catia_in.write("FreeLocalParam(all;Omega;false)\n")
    for frq in loop_frq():
        frq_label = int(frq * 1e-6)
        param = "R1iph_%s" % frq_label
        catia_in.write("FreeLocalParam(all;%s;false)\n" % param)
    catia_in.write("\n")

    # Minimisation.
    catia_in.write("Minimize(print=y;tol=%s;maxiter=%i)\n" % (f_tol, max_iter))
    catia_in.write("\n")

    # Plotting.
    catia_in.write("PrintParam(%s/GlobalParam.fit;global)\n" % output_dir)
    catia_in.write("PrintParam(%s/DeltaOmega.fit;DeltaO)\n" % output_dir)
    catia_in.write("PrintData(%s/)\n" % output_dir)
    catia_in.write("\n")

    # Calculate the chi-squared value (not sure why, it's calculated in the minimisation).
    catia_in.write("ChiSq(all;all)\n")

    # Exit the program.
    catia_in.write("exit(0)\n")

    # Close the file.
    catia_in.close()
Пример #7
0
def write_r2eff_files(input_dir=None, base_dir=None, force=False):
    """Create the CATIA R2eff input files.

    @keyword input_dir: The special directory for the R2eff input files.
    @type input_dir:    str
    @keyword base_dir:  The base directory to place the files into.
    @type base_dir:     str
    @keyword force:     A flag which if True will cause a pre-existing file to be overwritten.
    @type force:        bool
    """

    # Create the directory for the R2eff files for each field and spin.
    dir = base_dir + sep + input_dir
    mkdir_nofail(dir, verbosity=0)

    # Determine the isotope information.
    isotope = None
    for spin in spin_loop(skip_desel=True):
        if hasattr(spin, 'isotope'):
            if isotope == None:
                isotope = spin.isotope
            elif spin.isotope != isotope:
                raise RelaxError("CATIA only supports one spin type.")
    if isotope == None:
        raise RelaxError("The spin isotopes have not been specified.")

    # Isotope translation.
    if isotope == '1H':
        isotope = 'H1'
    elif isotope == '13C':
        isotope = 'C13'
    elif isotope == '15N':
        isotope = 'N15'

    # Loop over the frequencies.
    for frq, mi in loop_frq(return_indices=True):
        # The frequency string in MHz.
        frq_string = int(frq*1e-6)

        # The set files.
        file_name = "data_set_%i.inp" % frq_string
        set_file = open_write_file(file_name=file_name, dir=base_dir, force=force)
        id = frq_string
        set_file.write("ID=%s\n" % id)
        set_file.write("Sfrq = %s\n" % frq_string)
        set_file.write("Temperature = %s\n" % 0.0)
        set_file.write("Nucleus = %s\n" % isotope)
        set_file.write("Couplednucleus = %s\n" % 'H1')
        set_file.write("Time_equil = %s\n" % 0.0)
        set_file.write("Pwx_cp = %s\n" % 0.0)
        set_file.write("Taub = %s\n" % 0.0)
        set_file.write("Time_T2 = %s\n"% cdp.relax_time_list[0])
        set_file.write("Xcar = %s\n" % 0.0)
        set_file.write("Seqfil = %s\n" % 'CW_CPMG')
        set_file.write("Minerror = %s\n" % "(2.%;0.5/s)")
        set_file.write("Basis = (%s)\n" % "Iph_7")
        set_file.write("Format = (%i;%i;%i)\n" % (0, 1, 2))
        set_file.write("DataDirectory = %s\n" % (dir+sep))
        set_file.write("Data = (\n")

        # Loop over the spins.
        for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
            # The file.
            file_name = "spin%s_%i.cpmg" % (spin_id.replace('#', '_').replace(':', '_').replace('@', '_'), frq_string)
            spin_file = open_write_file(file_name=file_name, dir=dir, force=force)

            # Write the header.
            spin_file.write("# %18s %20s %20s\n" % ("nu_cpmg(Hz)", "R2(1/s)", "Esd(R2)"))

            # Loop over the dispersion points.
            for offset, point, oi, di in loop_offset_point(exp_type=EXP_TYPE_CPMG_SQ, frq=frq, return_indices=True):
                # The key.
                key = return_param_key_from_data(exp_type=EXP_TYPE_CPMG_SQ, frq=frq, offset=offset, point=point)

                # No data.
                if key not in spin.r2eff:
                    continue

                # Write out the data.
                spin_file.write("%20.15f %20.15f %20.15f\n" % (point, spin.r2eff[key], spin.r2eff_err[key]))

            # Close the file.
            spin_file.close()

            # Add the file name to the set.
            catia_spin_id = "%i%s" % (res_num, spin.name)
            set_file.write(" [%s;%s];\n" % (catia_spin_id, file_name))

        # Terminate the set file.
        set_file.write(")\n")
        set_file.close()
Пример #8
0
def write_main_file(file=None, dir=None, output_dir=None, f_tol=1e-25, max_iter=10000000, r1=False, force=False):
    """Create the main CATIA execution file.

    @keyword file:          The main CATIA execution file.
    @type file:             str
    @keyword dir:           The directory to place the files into.
    @type dir:              str or None
    @keyword output_dir:    The CATIA output directory, located within the directory specified by the dir argument.  This directory will be created.
    @type output_dir:       str
    @keyword r1:            A flag which if True will cause the R1 data to be used for off-resonance effects.
    @type r1:               bool
    @keyword force:         A flag which if True will cause a pre-existing file to be overwritten.
    @type force:            bool
    """

    # The file.
    catia_in = open_write_file(file_name=file, dir=dir, force=force)

    # The R2eff input sets.
    for frq in loop_frq():
        frq_label = int(frq*1e-6)
        file_name = "data_set_%i.inp" % frq_label
        catia_in.write("ReadDataset(%s)\n" % file_name)

    # Write out the data.
    catia_in.write("ReadParam_Global(ParamGlobal.inp)\n")
    catia_in.write("ReadParam_Local(ParamSet1.inp)\n")
    catia_in.write("\n")

    # The R1 data for off-resonance effects.
    if r1:
        catia_in.write("ReadParam(Omega;%s;0;1)\n" % shift_file)
        for frq in loop_frq():
            frq_label = int(frq*1e-6)
            param = "R1iph_%s" % frq_label
            r1_file = "R1_%s.out" % frq_label
            catia_in.write("ReadParam(%s;%s;0;1)\n" % (param, r1_file))
        catia_in.write("\n")

    # Fix these off-resonance parameters.
    catia_in.write("FreeLocalParam(all;Omega;false)\n")
    for frq in loop_frq():
        frq_label = int(frq*1e-6)
        param = "R1iph_%s" % frq_label
        catia_in.write("FreeLocalParam(all;%s;false)\n" % param)
    catia_in.write("\n")

    # Minimisation.
    catia_in.write("Minimize(print=y;tol=%s;maxiter=%i)\n" % (f_tol, max_iter))
    catia_in.write("\n")

    # Plotting.
    catia_in.write("PrintParam(%s/GlobalParam.fit;global)\n" % output_dir)
    catia_in.write("PrintParam(%s/DeltaOmega.fit;DeltaO)\n" % output_dir)
    catia_in.write("PrintData(%s/)\n" % output_dir)
    catia_in.write("\n")

    # Calculate the chi-squared value (not sure why, it's calculated in the minimisation).
    catia_in.write("ChiSq(all;all)\n")

    # Exit the program.
    catia_in.write("exit(0)\n")

    # Close the file.
    catia_in.close()