Exemplo n.º 1
0
    def test_return_molecule(self):
        """Test the function for returning the desired molecule data container.

        The function tested is pipe_control.mol_res_spin.return_molecule().
        """

        # Ask for a few molecules.
        mol1 = mol_res_spin.return_molecule('#Ap4Aase')
        mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig')

        # Test the data of molecule 1.
        self.assertEqual(mol1.name, 'Ap4Aase')

        # Test the data of molecule 2.
        self.assertEqual(mol2.name, 'RNA')
Exemplo n.º 2
0
    def test_return_molecule(self):
        """Test the function for returning the desired molecule data container.

        The function tested is pipe_control.mol_res_spin.return_molecule().
        """

        # Ask for a few molecules.
        mol1 = mol_res_spin.return_molecule('#Ap4Aase')
        mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig')

        # Test the data of molecule 1.
        self.assertEqual(mol1.name, 'Ap4Aase')

        # Test the data of molecule 2.
        self.assertEqual(mol2.name, 'RNA')
Exemplo n.º 3
0
    def action_molecule_type(self, event):
        """Launch the molecule.type user function.

        @param event:   The wx event.
        @type event:    wx event
        """

        # The current selection.
        item = self.element.GetFirstSelected()

        # The spectrum ID.
        id = gui_to_str(self.element.GetItemText(item))

        # The current type.
        type = None
        mol = return_molecule(id)
        if hasattr(mol, 'type') and mol.type != None:
            type = mol.type

        # Launch the dialog.
        if type == None:
            uf_store['molecule.type'](wx_parent=self.parent, mol_id=id)
        else:
            uf_store['molecule.type'](wx_parent=self.parent,
                                      mol_id=id,
                                      type=type)
Exemplo n.º 4
0
    def action_molecule_molecule_type(self, event):
        """Wrapper method.

        @param event:   The wx event.
        @type event:    wx event
        """

        # Get the current molecule type
        mol = return_molecule(self.info['id'])
        type = None
        if hasattr(mol, 'type'):
            type = mol.type

        # Launch the user function wizard.
        if type == None:
            uf_store['molecule.type'](wx_parent=self.gui.spin_viewer, mol_id=self.info['id'])
        else:
            uf_store['molecule.type'](wx_parent=self.gui.spin_viewer, mol_id=self.info['id'], type=type)
Exemplo n.º 5
0
    def action_molecule_molecule_type(self, event):
        """Wrapper method.

        @param event:   The wx event.
        @type event:    wx event
        """

        # Get the current molecule type
        mol = return_molecule(self.info['id'])
        type = None
        if hasattr(mol, 'type'):
            type = mol.type

        # Launch the user function wizard.
        if type == None:
            uf_store['molecule.type'](wx_parent=self.gui.spin_viewer, mol_id=self.info['id'])
        else:
            uf_store['molecule.type'](wx_parent=self.gui.spin_viewer, mol_id=self.info['id'], type=type)
Exemplo n.º 6
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
Exemplo n.º 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(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
Exemplo n.º 8
0
    def action_molecule_type(self, event):
        """Launch the molecule.type user function.

        @param event:   The wx event.
        @type event:    wx event
        """

        # The current selection.
        item = self.element.GetFirstSelected()

        # The spectrum ID.
        id = gui_to_str(self.element.GetItemText(item))

        # The current type.
        type = None
        mol = return_molecule(id)
        if hasattr(mol, 'type') and mol.type != None:
            type = mol.type

        # Launch the dialog.
        if type == None:
            uf_store['molecule.type'](wx_parent=self.parent, mol_id=id)
        else:
            uf_store['molecule.type'](wx_parent=self.parent, mol_id=id, type=type)
Exemplo n.º 9
0
def pipe_centre_of_mass(atom_id=None, model=None, return_mass=False, verbosity=1):
    """Calculate and return the centre of mass of the structures in the current data pipe.

    @keyword atom_id:       The molecule, residue, and atom identifier string.  Only atoms matching this selection will be used.
    @type atom_id:          str or None
    @keyword model:         Only use a specific model.
    @type model:            int or None
    @keyword return_mass:   A flag which if False will cause only the centre of mass to be returned, but if True will cause the centre of mass and the mass itself to be returned as a tuple.
    @type return_mass:      bool
    @keyword verbosity:     The amount of text to print out.  0 results in no printouts, 1 the full amount.
    @type verbosity:        int
    @return:                The centre of mass vector, and additionally the mass.
    @rtype:                 list of 3 floats (or tuple of a list of 3 floats and one float)
    """

    # Test if a structure has been loaded.
    if not hasattr(cdp, 'structure'):
        raise RelaxNoPdbError

    # Loop over all atoms.
    coord = []
    element_list = []
    for mol_name, res_num, res_name, atom_num, atom_name, element, pos in cdp.structure.atom_loop(atom_id=atom_id, model_num=model, 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=True):
        # Initialise the spin id string.
        id = ''

        # Get the corresponding molecule container.
        if mol_name == None:
            mol_cont = cdp.mol[0]
        else:
            id = id + '#' + mol_name
            mol_cont = return_molecule(id)

        # Get the corresponding residue container.
        if res_name == None and res_num == None:
            res_cont = mol_cont.res[0]
        else:
            id = id + ':' + repr(res_num)
            res_cont = return_residue(id)

        # Get the corresponding spin container.
        if atom_name == None and atom_num == None:
            spin_cont = res_cont.spin[0]
        else:
            id = id + '@' + repr(atom_num)
            spin_cont = return_spin(id)

        # Deselected spins.
        if spin_cont and not spin_cont.select:
            continue

        # No element?
        if element == None:
            warn(RelaxWarning("Skipping the atom '%s' as the element type cannot be determined." % id))
            continue

        # Store the position and element.
        coord.append(pos)
        element_list.append(element)

    # Calculate the CoM.
    com, mass = centre_of_mass(pos=coord, elements=element_list)

    # Return the centre of mass.
    if return_mass:
        return com, mass
    else:
        return com