Пример #1
0
    def rna_seq(self):
        """Generate the RNA sequence of the noe_rna_hbond.dat restraint file."""

        # Info.
        mol_names = ["A", "B"]
        res_nums = [[1, 2, 3, 4], [4, 3, 2, 1]]
        spin_names = [
            [["N1", "N6", "H62"], ["H3", "N3", "O4"], ["H1", "N1", "H22", "N2", "O6"], ["N3", "O2", "H42", "N4"]],
            [["H3", "N3", "O4"], ["N1", "N6", "H62"], ["N3", "O2", "H42", "N4"], ["H1", "N1", "H22", "N2", "O6"]],
        ]

        # Loop over the molecules.
        for i in range(len(mol_names)):
            # Create the molecule.
            create_molecule(mol_names[i])

            # Loop over the residues.
            for j in range(len(res_nums[i])):
                # Create the residue.
                create_residue(res_nums[i][j], mol_name=mol_names[i])

                # Loop over the atoms.
                for k in range(len(spin_names[i][j])):
                    # Create the spin.
                    create_spin(spin_names[i][j][k], res_num=res_nums[i][j], mol_name=mol_names[i])

        # Display the sequence for debugging.
        self.interpreter.sequence.display()
Пример #2
0
def read_spins(file=None, dir=None, dim=1, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, spin_id=None, verbose=True):
    """Read the peak intensity data.

    @keyword file:          The name of the file containing the peak intensities.
    @type file:             str
    @keyword dir:           The directory where the file is located.
    @type dir:              str
    @keyword dim:           The dimension of the peak list to associate the data with.
    @type dim:              int
    @keyword spin_id_col:   The column containing the spin ID strings (used by the generic intensity file format).  If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none.
    @type spin_id_col:      int or None
    @keyword mol_name_col:  The column containing the molecule name information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type mol_name_col:     int or None
    @keyword res_name_col:  The column containing the residue name information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type res_name_col:     int or None
    @keyword res_num_col:   The column containing the residue number information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type res_num_col:      int or None
    @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type spin_name_col:    int or None
    @keyword spin_num_col:  The column containing the spin number information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type spin_num_col:     int or None
    @keyword sep:           The column separator which, if None, defaults to whitespace.
    @type sep:              str or None
    @keyword spin_id:       The spin ID string used to restrict data loading to a subset of all spins.  If 'auto' is provided for a NMRPipe seriesTab formatted file, the ID's are auto generated in form of Z_Ai.
    @type spin_id:          None or str
    @keyword verbose:       A flag which if True will cause all relaxation data loaded to be printed out.
    @type verbose:          bool
    """

    # Data checks.
    check_pipe()

    # Check the file name.
    if file == None:
        raise RelaxError("The file name must be supplied.")

    # Read the peak list data.
    peak_list = read_peak_list(file=file, dir=dir, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep, spin_id=spin_id)

    # Loop over the peak_list.
    created_spins = []
    for assign in peak_list:
        mol_name = assign.mol_names[dim-1]
        res_num = assign.res_nums[dim-1]
        res_name = assign.res_names[dim-1]
        spin_num = assign.spin_nums[dim-1]
        spin_name = assign.spin_names[dim-1]

        # Generate the spin_id.
        spin_id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_name=spin_name)

        # Check if the spin already exist.
        if return_spin(spin_id=spin_id) == None:
            # Create the spin if not exist.
            create_spin(spin_num=spin_num, spin_name=spin_name, res_num=res_num, res_name=res_name, mol_name=mol_name)

    # Test that data exists.
    check_mol_res_spin_data()
Пример #3
0
def generate_sequence(N=0, spin_ids=None, spin_nums=None, spin_names=None, res_nums=None, res_names=None, mol_names=None, isotopes=None, elements=None):
    """Generate the sequence data from the BRMB information.

    @keyword N:             The number of spins.
    @type N:                int
    @keyword spin_ids:      The list of spin IDs.
    @type spin_ids:         list of str
    @keyword spin_nums:     The list of spin numbers.
    @type spin_nums:        list of int or None
    @keyword spin_names:    The list of spin names.
    @type spin_names:       list of str or None
    @keyword res_nums:      The list of residue numbers.
    @type res_nums:         list of int or None
    @keyword res_names:     The list of residue names.
    @type res_names:        list of str or None
    @keyword mol_names:     The list of molecule names.
    @type mol_names:        list of str or None
    @keyword isotopes:      The optional list of isotope types.
    @type isotopes:         list of str or None
    @keyword elements:      The optional list of element types.
    @type elements:         list of str or None
    """

    # The blank data.
    if not spin_nums:
        spin_nums = [None] * N
    if not spin_names:
        spin_names = [None] * N
    if not res_nums:
        res_nums = [None] * N
    if not res_names:
        res_names = [None] * N
    if not mol_names:
        mol_names = [None] * N

    # Generate the spin IDs.
    spin_ids = []
    for i in range(N):
        spin_ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], spin_name=spin_names[i]))

    # Loop over the spin data.
    for i in range(N):
        # The spin already exists.
        spin = return_spin(spin_ids[i])
        if spin:
            continue

        # Create the spin.
        spin = create_spin(spin_num=spin_nums[i], spin_name=spin_names[i], res_num=res_nums[i], res_name=res_names[i], mol_name=mol_names[i])

        # Set the spin isotope and element.
        spin_id = spin._spin_ids[0]
        if elements:
            set_spin_element(spin_id=spin_id, element=elements[i], force=True)
        if isotopes and elements:
            isotope = "%s%s" % (isotopes[i], elements[i])
            set_spin_isotope(spin_id=spin_id, isotope=isotope, force=True)

    # Clean up the spin metadata.
    metadata_cleanup()
Пример #4
0
    def rna_seq(self):
        """Generate the RNA sequence of the noe_rna_hbond.dat restraint file."""

        # Info.
        mol_names = ['A', 'B']
        res_nums = [
                [1, 2, 3, 4],
                [4, 3, 2, 1]
        ]
        spin_names = [
                [['N1', 'N6', 'H62'],
                 ['H3', 'N3', 'O4'],
                 ['H1', 'N1', 'H22', 'N2', 'O6'],
                 ['N3', 'O2', 'H42', 'N4']],
                [['H3', 'N3', 'O4'],
                 ['N1', 'N6', 'H62'],
                 ['N3', 'O2', 'H42', 'N4'],
                 ['H1', 'N1', 'H22', 'N2', 'O6']]
        ]
        
        # Loop over the molecules.
        for i in range(len(mol_names)):
            # Create the molecule.
            create_molecule(mol_names[i])

            # Loop over the residues.
            for j in range(len(res_nums[i])):
                # Create the residue.
                create_residue(res_nums[i][j], mol_name=mol_names[i])

                # Loop over the atoms.
                for k in range(len(spin_names[i][j])):
                    # Create the spin.
                    create_spin(spin_names[i][j][k], res_num=res_nums[i][j], mol_name=mol_names[i])

        # Display the sequence for debugging.
        self.interpreter.sequence.display()
Пример #5
0
def attach_protons():
    """Attach a single proton to all heteronuclei."""

    # Loop over all spins.
    mol_names = []
    res_nums = []
    res_names = []
    for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True):
        # The spin is already a proton.
        if hasattr(spin, 'element') and spin.element == 'H':
            continue

        # Get the interatomic data container.
        interatoms = return_interatom_list(spin_id)
        proton_found = False
        if len(interatoms):
            for i in range(len(interatoms)):
                # Get the attached spin.
                spin_attached = return_spin(interatoms[i].spin_id1)
                if id(spin_attached) == id(spin):
                    spin_attached = return_spin(interatoms[i].spin_id2)

                # Is it a proton?
                if hasattr(spin_attached, 'element') and spin_attached.element == 'H' or spin.name == 'H':
                    proton_found = True
                    break

        # Attached proton found.
        if proton_found:
            continue

        # Store the sequence info.
        mol_names.append(mol_name)
        res_nums.append(res_num)
        res_names.append(res_name)

    # Create all protons (this must be done out of the spin loop, as it affects the looping!).
    ids = []
    for i in range(len(mol_names)):
        # Create the spin container.
        spin = create_spin(spin_name='H', res_name=res_names[i], res_num=res_nums[i], mol_name=mol_names[i])
        ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name='H'))
    print("Creating the spins %s." % ids)

    # Set the element and spin type.
    set_spin_element(spin_id='@H', element='H')
    set_spin_isotope(spin_id='@H', isotope='1H')
Пример #6
0
def attach_protons():
    """Attach a single proton to all heteronuclei."""

    # Loop over all spins.
    mol_names = []
    res_nums = []
    res_names = []
    for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True):
        # The spin is already a proton.
        if hasattr(spin, 'element') and spin.element == 'H':
            continue

        # Get the interatomic data container.
        interatoms = return_interatom_list(spin_hash=spin._hash)
        proton_found = False
        if len(interatoms):
            for i in range(len(interatoms)):
                # Get the attached spin.
                spin_attached = return_spin(spin_hash=interatoms[i]._spin_hash1)
                if id(spin_attached) == id(spin):
                    spin_attached = return_spin(spin_hash=interatoms[i]._spin_hash2)

                # Is it a proton?
                if hasattr(spin_attached, 'element') and spin_attached.element == 'H' or spin.name == 'H':
                    proton_found = True
                    break

        # Attached proton found.
        if proton_found:
            continue

        # Store the sequence info.
        mol_names.append(mol_name)
        res_nums.append(res_num)
        res_names.append(res_name)

    # Create all protons (this must be done out of the spin loop, as it affects the looping!).
    ids = []
    for i in range(len(mol_names)):
        # Create the spin container.
        spin = create_spin(spin_name='H', res_name=res_names[i], res_num=res_nums[i], mol_name=mol_names[i])[0]
        ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name='H'))
    print("Creating the spins %s." % ids)

    # Set the element and spin type.
    set_spin_element(spin_id='@H', element='H')
    set_spin_isotope(spin_id='@H', isotope='1H')
Пример #7
0
def generate(mol_name=None, res_num=None, res_name=None, spin_num=None, spin_name=None, pipe=None, select=True, verbose=True):
    """Generate the sequence item-by-item by adding a single molecule/residue/spin container as necessary.

    @keyword mol_name:  The molecule name.
    @type mol_name:     str or None
    @keyword res_num:   The residue number.
    @type res_num:      int or None
    @keyword res_name:  The residue name.
    @type res_name:     str or None
    @keyword spin_num:  The spin number.
    @type spin_num:     int or None
    @keyword spin_name: The spin name.
    @type spin_name:    str or None
    @keyword pipe:      The data pipe in which to generate the sequence.  This defaults to the current data pipe.
    @type pipe:         str
    @keyword select:    The spin selection flag.
    @type select:       bool
    @keyword verbose:   A flag which if True will cause info about each spin to be printed out as the sequence is generated.
    @type verbose:      bool
    """

    # The current data pipe.
    if pipe == None:
        pipe = pipes.cdp_name()

    # A new molecule.
    if not return_molecule(generate_spin_id(mol_name=mol_name), pipe=pipe):
        create_molecule(mol_name=mol_name, pipe=pipe)

    # A new residue.
    curr_res = return_residue(generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name), pipe=pipe)
    if not curr_res or ((res_num != None and curr_res.num != res_num) or (res_name != None and curr_res.name != res_name)):
        create_residue(mol_name=mol_name, res_num=res_num, res_name=res_name, pipe=pipe)

    # A new spin.
    curr_spin = return_spin(generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name), pipe=pipe)
    if not curr_spin or ((spin_num != None and curr_spin.num != spin_num) or (spin_name != None and curr_spin.name != spin_name)):
        # Add the spin.
        curr_spin = create_spin(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name, pipe=pipe)

    # Set the selection flag.
    curr_spin.select = select
Пример #8
0
def generate(mol_name=None, res_num=None, res_name=None, spin_num=None, spin_name=None, pipe=None, select=True, verbose=True):
    """Generate the sequence item-by-item by adding a single molecule/residue/spin container as necessary.

    @keyword mol_name:  The molecule name.
    @type mol_name:     str or None
    @keyword res_num:   The residue number.
    @type res_num:      int or None
    @keyword res_name:  The residue name.
    @type res_name:     str or None
    @keyword spin_num:  The spin number.
    @type spin_num:     int or None
    @keyword spin_name: The spin name.
    @type spin_name:    str or None
    @keyword pipe:      The data pipe in which to generate the sequence.  This defaults to the current data pipe.
    @type pipe:         str
    @keyword select:    The spin selection flag.
    @type select:       bool
    @keyword verbose:   A flag which if True will cause info about each spin to be printed out as the sequence is generated.
    @type verbose:      bool
    """

    # The current data pipe.
    if pipe == None:
        pipe = pipes.cdp_name()

    # A new molecule.
    if not return_molecule(generate_spin_id(mol_name=mol_name), pipe=pipe):
        create_molecule(mol_name=mol_name, pipe=pipe)

    # A new residue.
    curr_res = return_residue(generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name), pipe=pipe)
    if not curr_res or ((res_num != None and curr_res.num != res_num) or (res_name != None and curr_res.name != res_name)):
        create_residue(mol_name=mol_name, res_num=res_num, res_name=res_name, pipe=pipe)

    # A new spin.
    curr_spin = return_spin(spin_id=generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name), pipe=pipe)
    if not curr_spin or ((spin_num != None and curr_spin.num != spin_num) or (spin_name != None and curr_spin.name != spin_name)):
        # Add the spin.
        curr_spin = create_spin(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name, pipe=pipe)[0]

    # Set the selection flag.
    curr_spin.select = select
Пример #9
0
def generate_sequence(N=0,
                      spin_ids=None,
                      spin_nums=None,
                      spin_names=None,
                      res_nums=None,
                      res_names=None,
                      mol_names=None,
                      isotopes=None,
                      elements=None):
    """Generate the sequence data from the BRMB information.

    @keyword N:             The number of spins.
    @type N:                int
    @keyword spin_ids:      The list of spin IDs.
    @type spin_ids:         list of str
    @keyword spin_nums:     The list of spin numbers.
    @type spin_nums:        list of int or None
    @keyword spin_names:    The list of spin names.
    @type spin_names:       list of str or None
    @keyword res_nums:      The list of residue numbers.
    @type res_nums:         list of int or None
    @keyword res_names:     The list of residue names.
    @type res_names:        list of str or None
    @keyword mol_names:     The list of molecule names.
    @type mol_names:        list of str or None
    @keyword isotopes:      The optional list of isotope types.
    @type isotopes:         list of str or None
    @keyword elements:      The optional list of element types.
    @type elements:         list of str or None
    """

    # The blank data.
    if not spin_nums:
        spin_nums = [None] * N
    if not spin_names:
        spin_names = [None] * N
    if not res_nums:
        res_nums = [None] * N
    if not res_names:
        res_names = [None] * N
    if not mol_names:
        mol_names = [None] * N

    # Generate the spin IDs.
    spin_ids = []
    for i in range(N):
        spin_ids.append(
            generate_spin_id(mol_name=mol_names[i],
                             res_num=res_nums[i],
                             spin_name=spin_names[i]))

    # Loop over the spin data.
    for i in range(N):
        # The spin already exists.
        spin = return_spin(spin_id=spin_ids[i])
        if spin:
            continue

        # Create the spin.
        spin = create_spin(spin_num=spin_nums[i],
                           spin_name=spin_names[i],
                           res_num=res_nums[i],
                           res_name=res_names[i],
                           mol_name=mol_names[i])[0]

        # Set the spin isotope and element.
        spin_id = spin._spin_ids[0]
        if elements:
            set_spin_element(spin_id=spin_id, element=elements[i], force=True)
        if isotopes and elements:
            isotope = "%s%s" % (isotopes[i], elements[i])
            set_spin_isotope(spin_id=spin_id, isotope=isotope, force=True)

    # Clean up the spin metadata.
    metadata_cleanup()
Пример #10
0
def copy(pipe_from=None, pipe_to=None, preserve_select=False, empty=True, verbose=True):
    """Copy the molecule, residue, and spin sequence data from one data pipe to another.

    @keyword pipe_from:         The data pipe to copy the sequence data from.  This defaults to the current data pipe.
    @type pipe_from:            str
    @keyword pipe_to:           The data pipe to copy the sequence data to.  This defaults to the current data pipe.
    @type pipe_to:              str
    @keyword preserve_select:   A flag which if True will cause spin selections to be preserved.
    @type preserve_select:      bool
    @keyword empty:             A flag which if True will create a molecule, residue, and spin sequence in the target pipe lacking all of the spin data of the source pipe.  If False, then the spin data will also be copied.
    @keyword verbose:           A flag which if True will cause info about each spin to be printed out as the sequence is generated.
    @type verbose:              bool
    """

    # Defaults.
    if pipe_from == None and pipe_to == None:
        raise RelaxError("The pipe_from and pipe_to arguments cannot both be set to None.")
    elif pipe_from == None:
        pipe_from = pipes.cdp_name()
    elif pipe_to == None:
        pipe_to = pipes.cdp_name()

    # Test if the pipe_from and pipe_to data pipes exist.
    check_pipe(pipe_from)
    check_pipe(pipe_to)

    # Test if pipe_from contains sequence data.
    if not exists_mol_res_spin_data(pipe_from):
        raise RelaxNoSequenceError

    # Test if pipe_to contains sequence data.
    if exists_mol_res_spin_data(pipe_to):
        raise RelaxSequenceError

    # Loop over the spins of the pipe_from data pipe.
    for spin, mol_name, res_num, res_name in spin_loop(pipe=pipe_from, full_info=True):
        # Generate the new sequence.
        new_spin = create_spin(spin_num=spin.num, spin_name=spin.name, res_num=res_num, res_name=res_name, mol_name=mol_name, pipe=pipe_to)

        # Preserve selection.
        if preserve_select:
            new_spin.select = spin.select
        else:
            select = True

        # Copy all the spin data.
        if not empty:
            # Duplicate all the objects of the container.
            for name in dir(spin):
                # Skip special objects.
                if search('^_', name):
                    continue

                # Skip the spin ID.
                #if name in ['spin_id']:
                #    continue

                # Skip class methods.
                if name in spin.__class__.__dict__:
                    continue

                # Duplicate all other objects.
                obj = deepcopy(getattr(spin, name))
                setattr(new_spin, name, obj)

    # Print out.
    if verbose:
        display(mol_name_flag=True, res_num_flag=True, res_name_flag=True, spin_num_flag=True, spin_name_flag=True)
Пример #11
0
def copy(pipe_from=None, pipe_to=None, preserve_select=False, empty=True, verbose=True):
    """Copy the molecule, residue, and spin sequence data from one data pipe to another.

    @keyword pipe_from:         The data pipe to copy the sequence data from.  This defaults to the current data pipe.
    @type pipe_from:            str
    @keyword pipe_to:           The data pipe to copy the sequence data to.  This defaults to the current data pipe.
    @type pipe_to:              str
    @keyword preserve_select:   A flag which if True will cause spin selections to be preserved.
    @type preserve_select:      bool
    @keyword empty:             A flag which if True will create a molecule, residue, and spin sequence in the target pipe lacking all of the spin data of the source pipe.  If False, then the spin data will also be copied.
    @keyword verbose:           A flag which if True will cause info about each spin to be printed out as the sequence is generated.
    @type verbose:              bool
    """

    # Defaults.
    if pipe_from == None and pipe_to == None:
        raise RelaxError("The pipe_from and pipe_to arguments cannot both be set to None.")
    elif pipe_from == None:
        pipe_from = pipes.cdp_name()
    elif pipe_to == None:
        pipe_to = pipes.cdp_name()

    # Test if the pipe_from and pipe_to data pipes exist.
    check_pipe(pipe_from)
    check_pipe(pipe_to)

    # Test if pipe_from contains sequence data.
    if not exists_mol_res_spin_data(pipe_from):
        raise RelaxNoSequenceError

    # Test if pipe_to contains sequence data.
    if exists_mol_res_spin_data(pipe_to):
        raise RelaxSequenceError

    # Loop over the spins of the pipe_from data pipe.
    for spin, mol_name, res_num, res_name in spin_loop(pipe=pipe_from, full_info=True):
        # Generate the new sequence.
        new_spin = create_spin(spin_num=spin.num, spin_name=spin.name, res_num=res_num, res_name=res_name, mol_name=mol_name, pipe=pipe_to)[0]

        # Preserve selection.
        if preserve_select:
            new_spin.select = spin.select
        else:
            select = True

        # Copy all the spin data.
        if not empty:
            # Duplicate all the objects of the container.
            for name in dir(spin):
                # Skip special objects.
                if search('^_', name):
                    continue

                # Skip the spin ID.
                #if name in ['spin_id']:
                #    continue

                # Skip class methods.
                if name in spin.__class__.__dict__:
                    continue

                # Duplicate all other objects.
                obj = deepcopy(getattr(spin, name))
                setattr(new_spin, name, obj)

    # Print out.
    if verbose:
        display(mol_name_flag=True, res_num_flag=True, res_name_flag=True, spin_num_flag=True, spin_name_flag=True)
Пример #12
0
def read_spins(file=None,
               dir=None,
               dim=1,
               spin_id_col=None,
               mol_name_col=None,
               res_num_col=None,
               res_name_col=None,
               spin_num_col=None,
               spin_name_col=None,
               sep=None,
               spin_id=None,
               verbose=True):
    """Read the peak intensity data.

    @keyword file:          The name of the file containing the peak intensities.
    @type file:             str
    @keyword dir:           The directory where the file is located.
    @type dir:              str
    @keyword dim:           The dimension of the peak list to associate the data with.
    @type dim:              int
    @keyword spin_id_col:   The column containing the spin ID strings (used by the generic intensity file format).  If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none.
    @type spin_id_col:      int or None
    @keyword mol_name_col:  The column containing the molecule name information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type mol_name_col:     int or None
    @keyword res_name_col:  The column containing the residue name information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type res_name_col:     int or None
    @keyword res_num_col:   The column containing the residue number information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type res_num_col:      int or None
    @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type spin_name_col:    int or None
    @keyword spin_num_col:  The column containing the spin number information (used by the generic intensity file format).  If supplied, spin_id_col must be None.
    @type spin_num_col:     int or None
    @keyword sep:           The column separator which, if None, defaults to whitespace.
    @type sep:              str or None
    @keyword spin_id:       The spin ID string used to restrict data loading to a subset of all spins.  If 'auto' is provided for a NMRPipe seriesTab formatted file, the ID's are auto generated in form of Z_Ai.
    @type spin_id:          None or str
    @keyword verbose:       A flag which if True will cause all relaxation data loaded to be printed out.
    @type verbose:          bool
    """

    # Data checks.
    check_pipe()

    # Check the file name.
    if file == None:
        raise RelaxError("The file name must be supplied.")

    # Read the peak list data.
    peak_list = read_peak_list(file=file,
                               dir=dir,
                               spin_id_col=spin_id_col,
                               mol_name_col=mol_name_col,
                               res_num_col=res_num_col,
                               res_name_col=res_name_col,
                               spin_num_col=spin_num_col,
                               spin_name_col=spin_name_col,
                               sep=sep,
                               spin_id=spin_id)

    # Loop over the peak_list.
    created_spins = []
    for assign in peak_list:
        mol_name = assign.mol_names[dim - 1]
        res_num = assign.res_nums[dim - 1]
        res_name = assign.res_names[dim - 1]
        spin_num = assign.spin_nums[dim - 1]
        spin_name = assign.spin_names[dim - 1]

        # Generate the spin_id.
        spin_id = generate_spin_id_unique(mol_name=mol_name,
                                          res_num=res_num,
                                          res_name=res_name,
                                          spin_name=spin_name)

        # Check if the spin already exist.
        if return_spin(spin_id=spin_id) == None:
            # Create the spin if not exist.
            create_spin(spin_num=spin_num,
                        spin_name=spin_name,
                        res_num=res_num,
                        res_name=res_name,
                        mol_name=mol_name)

    # Test that data exists.
    check_mol_res_spin_data()
Пример #13
0
    def _read_1_2_results(self, file_data, verbosity=1):
        """Read the relax 1.2 model-free results file.

        @param file_data:   The processed results file data.
        @type file_data:    list of lists of str
        @keyword verbosity: A variable specifying the amount of information to print.  The higher
                            the value, the greater the verbosity.
        @type verbosity:    int
        """

        # Extract and remove the header.
        header = file_data[0]
        file_data = file_data[1:]

        # Sort the column numbers.
        col = self._read_1_2_col_numbers(header)

        # Test the file.
        if len(col) < 2:
            raise RelaxInvalidDataError

        # Initialise some data structures and flags.
        sim_num = None
        sims = []
        all_select_sim = []
        diff_data_set = False
        diff_error_set = False
        diff_sim_set = None
        model_type = None
        pdb = False
        pdb_model = None
        pdb_heteronuc = None
        pdb_proton = None
        ri_labels = None

        # Generate the sequence.
        if verbosity:
            print("\nGenerating the sequence.")
        for file_line in file_data:
            # The data set.
            data_set = file_line[col['data_set']]

            # Stop creating the sequence once the data_set is no longer 'value'.
            if data_set != 'value':
                break

            # Sequence.
            self._generate_sequence(file_line, col, verbosity)

        # Count the number of simulations.
        for file_line in file_data:
            # The data set.
            data_set = file_line[col['data_set']]

            # Simulation number.
            if data_set != 'value' and data_set != 'error':
                # Extract the number from the data_set string.
                sim_num = data_set.split('_')
                try:
                    sim_num = int(sim_num[1])
                except:
                    raise RelaxError("The simulation number '%s' is invalid." % sim_num)
        if sim_num != None:
            cdp.sim_number = sim_num + 1

        # Loop over the lines of the file data.
        for file_line in file_data:
            # The data set.
            data_set = file_line[col['data_set']]

            # The spin info (for relax 1.2).
            if 'num' in col:
                mol_name = None
                res_num = int(file_line[col['num']])
                res_name = file_line[col['name']]
                spin_num = None
                spin_name = None
                if col['nucleus'] < len(file_line) and search('N', file_line[col['nucleus']]):
                    spin_name = 'N'
                if col['nucleus'] < len(file_line) and search('C', file_line[col['nucleus']]):
                    spin_name = 'C'

            # The spin info.
            else:
                mol_name = file_line[col['mol_name']]
                res_num = int(file_line[col['res_num']])
                res_name = file_line[col['res_name']]
                spin_num = int(file_line[col['spin_num']])
                spin_name = file_line[col['spin_name']]

            # Create the spin ID.
            spin_id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name)

            # Get the spin container.
            spin = return_spin(spin_id)

            # Create a new spin container for the proton, then set up a dipole interaction between the two spins.
            if data_set == 'value' and spin_name:
                h_spin = create_spin(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_name='H')
                h_spin.select = False
                h_spin.element = 'H'
                h_spin.isotope = '1H'
                spin_id2 = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_name='H')
                define(spin_id, spin_id2, verbose=False)

            # Backwards compatibility for the reading of the results file from versions 1.2.0 to 1.2.9.
            if len(file_line) == 4:
                continue

            # Set the nuclear isotope types and spin names (absent from the 1.2 results file).
            if data_set == 'value':
                if file_line[col['nucleus']] != 'None':
                    if search('N', file_line[col['nucleus']]):
                        spin.isotope = '15N'
                        if spin.name == None:
                            spin.name = 'N'
                    elif search('C', file_line[col['nucleus']]):
                        spin.isotope = '13C'
                        if spin.name == None:
                            spin.name = 'C'

            # Simulation number.
            if data_set != 'value' and data_set != 'error':
                # Extract the number from the data_set string.
                sim_num = data_set.split('_')
                try:
                    sim_num = int(sim_num[1])
                except:
                    raise RelaxError("The simulation number '%s' is invalid." % sim_num)

                # A new simulation number.
                if sim_num not in sims:
                    # Update the sims array and append an empty array to the selected sims array.
                    sims.append(sim_num)
                    all_select_sim.append([])

                # Selected simulations.
                all_select_sim[-1].append(bool(file_line[col['select']]))

                # Initial printout for the simulation.
                if verbosity:
                    if diff_sim_set == None:
                        print("\nLoading simulations.")
                    if sim_num != diff_sim_set:
                        print(data_set)

            # Diffusion tensor data.
            if data_set == 'value' and not diff_data_set:
                self._read_1_2_set_diff_tensor(file_line, col, data_set, verbosity, sim_num=sim_num)
                diff_data_set = True

            # Diffusion tensor errors.
            elif data_set == 'error' and not diff_error_set:
                self._read_1_2_set_diff_tensor(file_line, col, data_set, verbosity, sim_num=sim_num)
                diff_error_set = True

            # Diffusion tensor simulation data.
            elif data_set != 'value' and data_set != 'error' and sim_num != diff_sim_set:
                # Set up the diffusion tensor.
                if not hasattr(cdp.diff_tensor, '_sim_num') or cdp.diff_tensor._sim_num == None:
                    cdp.diff_tensor.set_sim_num(cdp.sim_number)

                self._read_1_2_set_diff_tensor(file_line, col, data_set, verbosity, sim_num=sim_num)
                diff_sim_set = sim_num

            # Model type.
            if model_type == None:
                self._fix_params(file_line, col, verbosity)

            # PDB.
            if not pdb:
                if self._load_structure(file_line, col, verbosity):
                    pdb = True

            # XH vector, heteronucleus, and proton.
            if data_set == 'value':
                self._set_xh_vect(file_line, col, spin, spin_id1=spin_id, spin_id2=spin_id2, verbosity=verbosity)

            # Relaxation data.
            self._load_relax_data(file_line, col, data_set, spin, verbosity)

            # Model-free data.
            self._load_model_free_data(file_line, col, data_set, spin, spin_id, verbosity)

        # Set up the simulations.
        if len(sims):
            # Convert the selected simulation array of arrays into a Numeric matrix, transpose it, then convert back to a Python list.
            all_select_sim = transpose(array(all_select_sim))
            all_select_sim = all_select_sim.tolist()

            # Set up the Monte Carlo simulations.
            pipe_control.monte_carlo.setup(number=len(sims), all_select_sim=all_select_sim)

            # Turn the simulation state to off!
            cdp.sim_state = False
Пример #14
0
def read_1_2_results(file_data, verbosity=1):
    """Read the relax 1.2 model-free results file.

    @param file_data:   The processed results file data.
    @type file_data:    list of lists of str
    @keyword verbosity: A variable specifying the amount of information to print.  The higher
                        the value, the greater the verbosity.
    @type verbosity:    int
    """

    # Extract and remove the header.
    header = file_data[0]
    file_data = file_data[1:]

    # Sort the column numbers.
    col = read_1_2_col_numbers(header)

    # Test the file.
    if len(col) < 2:
        raise RelaxInvalidDataError

    # Initialise some data structures and flags.
    sim_num = None
    sims = []
    all_select_sim = []
    diff_data_set = False
    diff_error_set = False
    diff_sim_set = None
    model_type = None
    pdb = False
    pdb_model = None
    pdb_heteronuc = None
    pdb_proton = None
    ri_labels = None

    # Generate the sequence.
    if verbosity:
        print("\nGenerating the sequence.")
    for file_line in file_data:
        # The data set.
        data_set = file_line[col['data_set']]

        # Stop creating the sequence once the data_set is no longer 'value'.
        if data_set != 'value':
            break

        # Sequence.
        generate_sequence(file_line, col, verbosity)

    # Count the number of simulations.
    for file_line in file_data:
        # The data set.
        data_set = file_line[col['data_set']]

        # Simulation number.
        if data_set != 'value' and data_set != 'error':
            # Extract the number from the data_set string.
            sim_num = data_set.split('_')
            try:
                sim_num = int(sim_num[1])
            except:
                raise RelaxError("The simulation number '%s' is invalid." %
                                 sim_num)
    if sim_num != None:
        cdp.sim_number = sim_num + 1

    # Loop over the lines of the file data.
    for file_line in file_data:
        # The data set.
        data_set = file_line[col['data_set']]

        # The spin info (for relax 1.2).
        if 'num' in col:
            mol_name = None
            res_num = int(file_line[col['num']])
            res_name = file_line[col['name']]
            spin_num = None
            spin_name = None
            if col['nucleus'] < len(file_line) and search(
                    'N', file_line[col['nucleus']]):
                spin_name = 'N'
            if col['nucleus'] < len(file_line) and search(
                    'C', file_line[col['nucleus']]):
                spin_name = 'C'

        # The spin info.
        else:
            mol_name = file_line[col['mol_name']]
            res_num = int(file_line[col['res_num']])
            res_name = file_line[col['res_name']]
            spin_num = int(file_line[col['spin_num']])
            spin_name = file_line[col['spin_name']]

        # Create the spin ID.
        spin_id = generate_spin_id_unique(mol_name=mol_name,
                                          res_num=res_num,
                                          res_name=res_name,
                                          spin_num=spin_num,
                                          spin_name=spin_name)

        # Get the spin container.
        spin = return_spin(spin_id=spin_id)

        # Create a new spin container for the proton, then set up a dipole interaction between the two spins.
        if data_set == 'value' and spin_name:
            h_spin = create_spin(mol_name=mol_name,
                                 res_num=res_num,
                                 res_name=res_name,
                                 spin_name='H')[0]
            h_spin.select = False
            h_spin.element = 'H'
            h_spin.isotope = '1H'
            spin_id2 = generate_spin_id_unique(mol_name=mol_name,
                                               res_num=res_num,
                                               res_name=res_name,
                                               spin_name='H')
            define_dipole_pair(spin_id1=spin_id,
                               spin_id2=spin_id2,
                               spin1=spin,
                               spin2=h_spin,
                               verbose=False)

        # Backwards compatibility for the reading of the results file from versions 1.2.0 to 1.2.9.
        if len(file_line) == 4:
            continue

        # Set the nuclear isotope types and spin names (absent from the 1.2 results file).
        if data_set == 'value':
            if file_line[col['nucleus']] != 'None':
                if search('N', file_line[col['nucleus']]):
                    spin.isotope = '15N'
                    if spin.name == None:
                        spin.name = 'N'
                elif search('C', file_line[col['nucleus']]):
                    spin.isotope = '13C'
                    if spin.name == None:
                        spin.name = 'C'

        # Simulation number.
        if data_set != 'value' and data_set != 'error':
            # Extract the number from the data_set string.
            sim_num = data_set.split('_')
            try:
                sim_num = int(sim_num[1])
            except:
                raise RelaxError("The simulation number '%s' is invalid." %
                                 sim_num)

            # A new simulation number.
            if sim_num not in sims:
                # Update the sims array and append an empty array to the selected sims array.
                sims.append(sim_num)
                all_select_sim.append([])

            # Selected simulations.
            all_select_sim[-1].append(bool(file_line[col['select']]))

            # Initial printout for the simulation.
            if verbosity:
                if diff_sim_set == None:
                    print("\nLoading simulations.")
                if sim_num != diff_sim_set:
                    print(data_set)

        # Diffusion tensor data.
        if data_set == 'value' and not diff_data_set:
            read_1_2_set_diff_tensor(file_line,
                                     col,
                                     data_set,
                                     verbosity,
                                     sim_num=sim_num)
            diff_data_set = True

        # Diffusion tensor errors.
        elif data_set == 'error' and not diff_error_set:
            read_1_2_set_diff_tensor(file_line,
                                     col,
                                     data_set,
                                     verbosity,
                                     sim_num=sim_num)
            diff_error_set = True

        # Diffusion tensor simulation data.
        elif data_set != 'value' and data_set != 'error' and sim_num != diff_sim_set:
            # Set up the diffusion tensor.
            if not hasattr(cdp.diff_tensor,
                           '_sim_num') or cdp.diff_tensor._sim_num == None:
                cdp.diff_tensor.set_sim_num(cdp.sim_number)

            read_1_2_set_diff_tensor(file_line,
                                     col,
                                     data_set,
                                     verbosity,
                                     sim_num=sim_num)
            diff_sim_set = sim_num

        # Model type.
        if model_type == None:
            fix_params(file_line, col, verbosity)

        # PDB.
        if not pdb:
            if load_structure(file_line, col, verbosity):
                pdb = True

        # XH vector, heteronucleus, and proton.
        if data_set == 'value':
            set_xh_vect(file_line,
                        col,
                        spin,
                        spin_id1=spin_id,
                        spin_id2=spin_id2,
                        spin_hash1=spin._hash,
                        spin_hash2=h_spin._hash,
                        verbosity=verbosity)

        # Relaxation data.
        load_relax_data(file_line, col, data_set, spin, verbosity)

        # Model-free data.
        load_model_free_data(file_line, col, data_set, spin, spin_id,
                             verbosity)

    # Set up the simulations.
    if len(sims):
        # Convert the selected simulation array of arrays into a Numeric matrix, transpose it, then convert back to a Python list.
        all_select_sim = transpose(array(all_select_sim))
        all_select_sim = all_select_sim.tolist()

        # Set up the Monte Carlo simulations.
        pipe_control.error_analysis.monte_carlo_setup(
            number=len(sims), all_select_sim=all_select_sim)

        # Turn the simulation state to off!
        cdp.sim_state = False
Пример #15
0
def load_spins(spin_id=None, str_id=None, mol_name_target=None, ave_pos=False):
    """Load the spins from the structural object into the relax data store.

    @keyword spin_id:           The molecule, residue, and spin identifier string.
    @type spin_id:              str
    @keyword str_id:            The structure identifier.  This can be the file name, model number, or structure number.
    @type str_id:               int or str
    @keyword mol_name:          The name of target molecule container, overriding the name of the loaded structures
    @type mol_name:             str or None
    @keyword ave_pos:           A flag specifying if the average atom position or the atom position from all loaded structures is loaded into the SpinContainer.
    @type ave_pos:              bool
    """

    # Test if the current data pipe exists.
    pipes.test()

    # Test if the structure exists.
    if not hasattr(cdp, 'structure') or not cdp.structure.num_models() or not cdp.structure.num_molecules():
        raise RelaxNoPdbError

    # Print out.
    print("Adding the following spins to the relax data store.\n")

    # Init the data for printing out.
    mol_names = []
    res_nums = []
    res_names = []
    spin_nums = []
    spin_names = []

    # Loop over all atoms of the spin_id selection.
    for mol_name, res_num, res_name, atom_num, atom_name, element, pos in cdp.structure.atom_loop(atom_id=spin_id, str_id=str_id, mol_name_flag=True, res_num_flag=True, res_name_flag=True, atom_num_flag=True, atom_name_flag=True, element_flag=True, pos_flag=True, ave=ave_pos):
        # Override the molecule name.
        if mol_name_target:
            mol_name = mol_name_target

        # Remove the '+' regular expression character from the mol, res, and spin names!
        if mol_name and search('\+', mol_name):
            mol_name = mol_name.replace('+', '')
        if res_name and search('\+', res_name):
            res_name = res_name.replace('+', '')
        if atom_name and search('\+', atom_name):
            atom_name = atom_name.replace('+', '')

        # Generate a spin ID for the current atom.
        id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=atom_num, spin_name=atom_name)

        # Create the spin.
        try:
            spin_cont = create_spin(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=atom_num, spin_name=atom_name)

        # Otherwise, get the spin container.
        except RelaxError:
            spin_cont = return_spin(id)

        # Append all the spin ID info for printing later.
        if mol_name_target:
            mol_names.append(mol_name_target)
        else:
            mol_names.append(mol_name)
        res_nums.append(res_num)
        res_names.append(res_name)
        spin_nums.append(atom_num)
        spin_names.append(atom_name)

        # Position vector.
        spin_cont.pos = pos

        # Add the element.
        spin_cont.element = element

    # Catch no data.
    if len(mol_names) == 0:
        warn(RelaxWarning("No spins matching the '%s' ID string could be found." % spin_id))
        return

    # Print out.
    write_spin_data(file=sys.stdout, mol_names=mol_names, res_nums=res_nums, res_names=res_names, spin_nums=spin_nums, spin_names=spin_names)