Author: bugman Date: Tue Jun 26 17:45:56 2012 New Revision: 17064 URL: http://svn.gna.org/viewcvs/relax?rev=17064&view=rev Log: Interatomic data containers can now be selected and deselected. The user functions select.interatom and deselect.interatom have been created mimicking the equivalent select.spin and deselect.spin functions. Each interatomic data container now has a select flag. Modified: branches/interatomic/data/interatomic.py branches/interatomic/generic_fns/selection.py branches/interatomic/user_functions/deselect.py branches/interatomic/user_functions/select.py Modified: branches/interatomic/data/interatomic.py URL: http://svn.gna.org/viewcvs/relax/branches/interatomic/data/interatomic.py?rev=17064&r1=17063&r2=17064&view=diff ============================================================================== --- branches/interatomic/data/interatomic.py (original) +++ branches/interatomic/data/interatomic.py Tue Jun 26 17:45:56 2012 @@ -37,13 +37,15 @@ class InteratomContainer(Prototype): """Class containing the interatomic data.""" - def __init__(self, spin_id1=None, spin_id2=None): + def __init__(self, spin_id1=None, spin_id2=None, select=True): """Set up the objects of the interatomic data container. @keyword spin_id1: The spin ID string of the first atom. @type spin_id1: str - @keyword spin_id2: The spin ID string of the first atom. + @keyword spin_id2: The spin ID string of the second atom. @type spin_id2: str + @keyword select: The selection flag. + @type select: bool """ # Store the spin IDs. @@ -52,6 +54,7 @@ # Class variable defaults. self.dipole_pair = False + self.select = select def __repr__(self): Modified: branches/interatomic/generic_fns/selection.py URL: http://svn.gna.org/viewcvs/relax/branches/interatomic/generic_fns/selection.py?rev=17064&r1=17063&r2=17064&view=diff ============================================================================== --- branches/interatomic/generic_fns/selection.py (original) +++ branches/interatomic/generic_fns/selection.py Tue Jun 26 17:45:56 2012 @@ -37,9 +37,9 @@ boolean_doc = Desc_container("Boolean operators") -boolean_doc.add_paragraph("The boolean operator can be used to change how spin systems are selected. The allowed values are: 'OR', 'NOR', 'AND', 'NAND', 'XOR', 'XNOR'. The following table details how the selections will occur for the different boolean operators.") +boolean_doc.add_paragraph("The boolean operator can be used to change how spin systems or interatomic data containers are selected. The allowed values are: 'OR', 'NOR', 'AND', 'NAND', 'XOR', 'XNOR'. The following table details how the selections will occur for the different boolean operators.") table = uf_tables.add_table(label="table: bool operators", caption="Boolean operators and their effects on selections") -table.add_headings(["Spin system", "1", "2", "3", "4", "5", "6", "7", "8", "9"]) +table.add_headings(["Spin system or interatomic data container", "1", "2", "3", "4", "5", "6", "7", "8", "9"]) table.add_row(["Original selection", "0", "1", "1", "1", "1", "0", "1", "0", "1"]) table.add_row(["New selection", "0", "1", "1", "1", "1", "1", "0", "0", "0"]) table.add_row(["OR", "0", "1", "1", "1", "1", "1", "1", "0", "1"]) @@ -67,6 +67,58 @@ # Loop over the spins and deselect them. for spin in spin_loop(): spin.select = False + + +def desel_interatom(spin_id1=None, spin_id2=None, boolean='AND', change_all=False): + """Deselect specific interatomic data containers. + + @keyword spin_id1: The spin ID string of the first spin of the pair. + @type spin_id1: str or None + @keyword spin_id2: The spin ID string of the second spin of the pair. + @type spin_id2: str or None + @param boolean: The boolean operator used to deselect the spin systems with. It can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'. This will be ignored if the change_all flag is set. + @type boolean: str + @keyword change_all: A flag which if True will cause all spins not specified in the file to be selected. Only the boolean operator 'AND' is compatible with this flag set to True (all others will be ignored). + @type change_all: bool + @raises RelaxNoSequenceError: If no molecule/residue/spins sequence data exists. + @raises RelaxError: If the boolean operator is unknown. + """ + + # Test if the current data pipe exists. + pipes.test() + + # Test if sequence data is loaded. + if not exists_mol_res_spin_data(): + raise RelaxNoSequenceError + + # First select all interatom containers if the change_all flag is set. + if change_all: + # Interatomic data loop. + for interatom in interatomic_loop(): + interatom.select = True + + # Interatomic data loop. + for interatom in interatomic_loop(spin_id1=spin_id1, spin_id2=spin_id2): + # Deselect just the specified residues. + if change_all: + interatom.select = False + + # Boolean selections. + else: + if boolean == 'OR': + interatom.select = interatom.select or False + elif boolean == 'NOR': + interatom.select = not (interatom.select or False) + elif boolean == 'AND': + interatom.select = interatom.select and False + elif boolean == 'NAND': + interatom.select = not (interatom.select and False) + elif boolean == 'XOR': + interatom.select = not (interatom.select and False) and (interatom.select or False) + elif boolean == 'XNOR': + interatom.select = (interatom.select and False) or not (interatom.select or False) + else: + raise RelaxError("Unknown boolean operator " + repr(boolean)) def desel_read(file=None, dir=None, file_data=None, 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, boolean='AND', change_all=False): @@ -309,6 +361,58 @@ spin.select = True +def sel_interatom(spin_id1=None, spin_id2=None, boolean='OR', change_all=False): + """Select specific interatomic data containers. + + @keyword spin_id1: The spin ID string of the first spin of the pair. + @type spin_id1: str or None + @keyword spin_id2: The spin ID string of the second spin of the pair. + @type spin_id2: str or None + @param boolean: The boolean operator used to select the spin systems with. It can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'. This will be ignored if the change_all flag is set. + @type boolean: str + @keyword change_all: A flag which if True will cause all spins not specified in the file to be deselected. Only the boolean operator 'OR' is compatible with this flag set to True (all others will be ignored). + @type change_all: bool + @raises RelaxNoSequenceError: If no molecule/residue/spins sequence data exists. + @raises RelaxError: If the boolean operator is unknown. + """ + + # Test if the current data pipe exists. + pipes.test() + + # Test if sequence data is loaded. + if not exists_mol_res_spin_data(): + raise RelaxNoSequenceError + + # First deselect all interatom containers if the change_all flag is set. + if change_all: + # Interatomic data loop. + for interatom in interatomic_loop(): + interatom.select = False + + # Interatomic data loop. + for interatom in interatomic_loop(spin_id1=spin_id1, spin_id2=spin_id2): + # Select just the specified containers. + if change_all: + interatom.select = True + + # Boolean selections. + else: + if boolean == 'OR': + interatom.select = interatom.select or True + elif boolean == 'NOR': + interatom.select = not (interatom.select or True) + elif boolean == 'AND': + interatom.select = interatom.select and True + elif boolean == 'NAND': + interatom.select = not (interatom.select and True) + elif boolean == 'XOR': + interatom.select = not (interatom.select and True) and (interatom.select or True) + elif boolean == 'XNOR': + interatom.select = (interatom.select and True) or not (interatom.select or True) + else: + raise RelaxError("Unknown boolean operator " + repr(boolean)) + + def sel_read(file=None, dir=None, file_data=None, 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, boolean='OR', change_all=False): """Select the spins contained in the given file. Modified: branches/interatomic/user_functions/deselect.py URL: http://svn.gna.org/viewcvs/relax/branches/interatomic/user_functions/deselect.py?rev=17064&r1=17063&r2=17064&view=diff ============================================================================== --- branches/interatomic/user_functions/deselect.py (original) +++ branches/interatomic/user_functions/deselect.py Tue Jun 26 17:45:56 2012 @@ -56,6 +56,68 @@ uf.menu_text = "&all" uf.wizard_size = (600, 550) uf.wizard_apply_button = False +uf.wizard_image = WIZARD_IMAGE_PATH + 'deselect.png' + + +# The deselect.interatom user function. +uf = uf_info.add_uf("deselect.interatom") +uf.title = "Deselect specific interatomic data containers." +uf.title_short = "Interatomic data container deselection." +uf.display = True +uf.add_keyarg( + name = "spin_id1", + py_type = "str", + arg_type = "spin ID", + desc_short = "first spin ID string", + desc = "The spin ID string of the first spin of the interatomic data container." +) +uf.add_keyarg( + name = "spin_id2", + py_type = "str", + arg_type = "spin ID", + desc_short = "second spin ID string", + desc = "The spin ID string of the second spin of the interatomic data container." +) +uf.add_keyarg( + name = "boolean", + default = "AND", + py_type = "str", + desc_short = "boolean operator", + desc = "The boolean operator specifying how interatomic data containers should be selected.", + wiz_element_type = "combo", + wiz_combo_choices = [ + "OR", + "NOR", + "AND", + "NAND", + "XOR", + "XNOR" + ], + wiz_read_only = True +) +uf.add_keyarg( + name = "change_all", + default = False, + py_type = "bool", + desc_short = "change all", + desc = "A flag specifying if all other interatomic data containers should be changed." +) +# Description. +uf.desc.append(Desc_container()) +uf.desc[-1].add_paragraph("This is used to deselect specific interatomic data containers which store information about spin pairs such as RDCs, NOEs, dipole-dipole pairs involved in relaxation, etc. The 'change all' flag default is False meaning that all interatomic data containers currently either selected or deselected will remain that way. Setting this to True will cause all interatomic data containers not specified by the spin ID strings to be deselected.") +uf.desc.append(selection.boolean_doc) +# Prompt examples. +uf.desc.append(Desc_container("Prompt examples")) +uf.desc[-1].add_paragraph("To deselect all N-H backbone bond vectors of a protein, assuming these interatomic data containers have been already set up, type one of:") +uf.desc[-1].add_prompt("relax> deselect.interatom('@N', '@H')") +uf.desc[-1].add_prompt("relax> deselect.interatom(spin_id1='@N', spin_id2='@H')") +uf.desc[-1].add_paragraph("To deselect all H-H interatomic vectors of a small organic molecule, type one of:") +uf.desc[-1].add_prompt("relax> deselect.interatom('@H*', '@H*')") +uf.desc[-1].add_prompt("relax> deselect.interatom(spin_id1='@H*', spin_id2='@H*')") +uf.backend = selection.desel_interatom +uf.menu_text = "&interatom" +uf.wizard_height_desc = 450 +uf.wizard_size = (1000, 750) uf.wizard_image = WIZARD_IMAGE_PATH + 'deselect.png' @@ -255,7 +317,7 @@ ) # Description. uf.desc.append(Desc_container()) -uf.desc[-1].add_paragraph("The 'change all' flag default is False meaning that all spins currently either selected or deselected will remain that way. Setting this to True will cause all spins not specified by the spin ID string to be selected.") +uf.desc[-1].add_paragraph("The 'change all' flag default is False meaning that all spins currently either selected or deselected will remain that way. Setting this to True will cause all spins not specified by the spin ID string to be deselected.") uf.desc.append(selection.boolean_doc) # Prompt examples. uf.desc.append(Desc_container("Prompt examples")) Modified: branches/interatomic/user_functions/select.py URL: http://svn.gna.org/viewcvs/relax/branches/interatomic/user_functions/select.py?rev=17064&r1=17063&r2=17064&view=diff ============================================================================== --- branches/interatomic/user_functions/select.py (original) +++ branches/interatomic/user_functions/select.py Tue Jun 26 17:45:56 2012 @@ -56,6 +56,68 @@ uf.menu_text = "&all" uf.wizard_size = (600, 550) uf.wizard_apply_button = False +uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' + + +# The select.interatom user function. +uf = uf_info.add_uf("select.interatom") +uf.title = "Select specific interatomic data containers." +uf.title_short = "Interatomic data container selection." +uf.display = True +uf.add_keyarg( + name = "spin_id1", + py_type = "str", + arg_type = "spin ID", + desc_short = "first spin ID string", + desc = "The spin ID string of the first spin of the interatomic data container." +) +uf.add_keyarg( + name = "spin_id2", + py_type = "str", + arg_type = "spin ID", + desc_short = "second spin ID string", + desc = "The spin ID string of the second spin of the interatomic data container." +) +uf.add_keyarg( + name = "boolean", + default = "OR", + py_type = "str", + desc_short = "boolean operator", + desc = "The boolean operator specifying how interatomic data containers should be selected.", + wiz_element_type = "combo", + wiz_combo_choices = [ + "OR", + "NOR", + "AND", + "NAND", + "XOR", + "XNOR" + ], + wiz_read_only = True +) +uf.add_keyarg( + name = "change_all", + default = False, + py_type = "bool", + desc_short = "change all", + desc = "A flag specifying if all other interatomic data containers should be changed." +) +# Description. +uf.desc.append(Desc_container()) +uf.desc[-1].add_paragraph("This is used to select specific interatomic data containers which store information about spin pairs such as RDCs, NOEs, dipole-dipole pairs involved in relaxation, etc. The 'change all' flag default is False meaning that all interatomic data containers currently either selected or deselected will remain that way. Setting this to True will cause all interatomic data containers not specified by the spin ID strings to be selected.") +uf.desc.append(selection.boolean_doc) +# Prompt examples. +uf.desc.append(Desc_container("Prompt examples")) +uf.desc[-1].add_paragraph("To select all N-H backbone bond vectors of a protein, assuming these interatomic data containers have been already set up, type one of:") +uf.desc[-1].add_prompt("relax> select.interatom('@N', '@H')") +uf.desc[-1].add_prompt("relax> select.interatom(spin_id1='@N', spin_id2='@H')") +uf.desc[-1].add_paragraph("To select all H-H interatomic vectors of a small organic molecule, type one of:") +uf.desc[-1].add_prompt("relax> select.interatom('@H*', '@H*')") +uf.desc[-1].add_prompt("relax> select.interatom(spin_id1='@H*', spin_id2='@H*')") +uf.backend = selection.sel_interatom +uf.menu_text = "&interatom" +uf.wizard_height_desc = 450 +uf.wizard_size = (1000, 750) uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png'