mailr18573 - in /trunk: generic_fns/structure/main.py user_functions/structure.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on February 27, 2013 - 19:40:
Author: bugman
Date: Wed Feb 27 19:40:48 2013
New Revision: 18573

URL: http://svn.gna.org/viewcvs/relax?rev=18573&view=rev
Log:
Created the structure.web_of_motion user function.

This is used to create a special PDB file which represents the atomic motions 
between different
structural models.  Identical atoms of the selected models are concatenated 
into one model, within
a temporary internal structural object, and linked together using PDB CONECT 
records.


Modified:
    trunk/generic_fns/structure/main.py
    trunk/user_functions/structure.py

Modified: trunk/generic_fns/structure/main.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/main.py?rev=18573&r1=18572&r2=18573&view=diff
==============================================================================
--- trunk/generic_fns/structure/main.py (original)
+++ trunk/generic_fns/structure/main.py Wed Feb 27 19:40:48 2013
@@ -916,6 +916,81 @@
         raise RelaxError("No vectors could be extracted.")
 
 
+def web_of_motion(file=None, dir=None, models=None, force=False):
+    """Create a PDB representation of the motion between a set of models.
+
+    This will create a PDB file containing the atoms of all models, with 
identical atoms links using CONECT records.  This function only supports the 
internal structural object.
+
+    @keyword file:          The name of the PDB file to write.
+    @type file:             str
+    @keyword dir:           The directory where the PDB file will be placed. 
 If set to None, then the file will be placed in the current directory.
+    @type dir:              str or None
+    @keyword models:        The optional list of models to restrict this to.
+    @type models:           list of int or None
+    @keyword force:         The force flag which if True will cause the file 
to be overwritten.
+    @type force:            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
+
+    # Validate the models.
+    cdp.structure.validate_models()
+
+    # Check the structural object type.
+    if cdp.structure.id != 'internal':
+        raise RelaxError("The %s structure type is not supported." % 
cdp.structure.id)
+
+    # Initialise the structural object.
+    web = Internal()
+
+    # Loop over the molecules.
+    for i in range(len(cdp.structure.structural_data[0].mol)):
+        # Alias the molecule of the first model.
+        mol1 = cdp.structure.structural_data[0].mol[i]
+
+        # Loop over the atoms.
+        for j in range(len(mol1.atom_name)):
+            # Loop over the models.
+            for k in range(len(cdp.structure.structural_data)):
+                # Alias.
+                mol = cdp.structure.structural_data[k].mol[i]
+
+                # Add the atom.
+                web.add_atom(mol_name=mol1.mol_name, 
atom_name=mol.atom_name[j], res_name=mol.res_name[j], res_num=mol.res_num[j], 
pos=[mol.x[j], mol.y[j], mol.z[j]], element=mol.element[j], 
chain_id=mol.chain_id[j], segment_id=mol.seg_id[j], 
pdb_record=mol.pdb_record[j])
+
+            # Loop over the models again, this time twice.
+            for k in range(len(cdp.structure.structural_data)):
+                for l in range(len(cdp.structure.structural_data)):
+                    # Skip identical atoms.
+                    if k == l:
+                        continue
+
+                    # The atom index.
+                    index1 = j*len(cdp.structure.structural_data) + l
+                    index2 = j*len(cdp.structure.structural_data) + k
+
+                    # Connect to the previous atoms.
+                    web.connect_atom(mol_name=mol1.mol_name, index1=index1, 
index2=index2)
+
+    # The file path.
+    file_path = get_file_path(file, dir)
+
+    # Add '.pdb' to the end of the file path if it isn't there yet.
+    if not search(".pdb$", file_path):
+        file_path = file_path + '.pdb'
+
+    # Open the file for writing.
+    file = open_write_file(file_path, force=force)
+
+    # Write the structure.
+    web.write_pdb(file)
+
+
 def write_pdb(file=None, dir=None, model_num=None, compress_type=0, 
force=False):
     """The PDB writing function.
 

Modified: trunk/user_functions/structure.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/user_functions/structure.py?rev=18573&r1=18572&r2=18573&view=diff
==============================================================================
--- trunk/user_functions/structure.py (original)
+++ trunk/user_functions/structure.py Wed Feb 27 19:40:48 2013
@@ -838,6 +838,57 @@
 uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'
 
 
+# The structure.web_of_motion user function.
+uf = uf_info.add_uf('structure.web_of_motion')
+uf.title = "Create a PDB representation of motion between models using a web 
of interconnecting lines."
+uf.title_short = "Web of motion between models."
+uf.add_keyarg(
+    name = "file",
+    py_type = "str",
+    arg_type = "file sel",
+    desc_short = "file name",
+    desc = "The name of the PDB file.",
+    wiz_filesel_wildcard = "PDB files (*.pdb)|*.pdb;*.PDB",
+    wiz_filesel_style = FD_SAVE
+)
+uf.add_keyarg(
+    name = "dir",
+    py_type = "str",
+    arg_type = "dir",
+    desc_short = "directory name",
+    desc = "The directory to save the file to.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "models",
+    py_type = "int_list",
+    desc_short = "model numbers",
+    desc = "Restrict the web to a subset of models.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "force",
+    default = False,
+    py_type = "bool",
+    desc_short = "force flag",
+    desc = "A flag which if set to True will cause any pre-existing files to 
be overwritten."
+)
+# Description.
+uf.desc.append(Desc_container())
+uf.desc[-1].add_paragraph("This will create a PDB representation of the 
motion between the atoms of a given set of structural models.  Identical 
atoms of the selected models are concatenated into one model, within a 
temporary internal structural object, and linked together using PDB CONECT 
records.")
+# Prompt examples.
+uf.desc.append(Desc_container("Prompt examples"))
+uf.desc[-1].add_paragraph("To create a web of motion for the models 1, 3, 
and 5, type one of:")
+uf.desc[-1].add_prompt("relax> structure.web_of_motion('web.pdb', '.', [1, 
3, 5])")
+uf.desc[-1].add_prompt("relax> structure.web_of_motion(file='web.pdb', 
models=[1, 3, 5])")
+uf.desc[-1].add_prompt("relax> structure.web_of_motion(file='web.pdb', 
dir='.', models=[1, 3, 5])")
+uf.backend = generic_fns.structure.main.web_of_motion
+uf.menu_text = "&web_of_motion"
+uf.wizard_size = (900, 600)
+uf.wizard_apply_button = False
+uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'
+
+
 # The structure.write_pdb user function.
 uf = uf_info.add_uf('structure.write_pdb')
 uf.title = "Writing structures to a PDB file."




Related Messages


Powered by MHonArc, Updated Wed Feb 27 20:00:04 2013