mailr2454 - in /1.2: errors.py generic_fns/molmol.py prompt/molmol.py specific_fns/model_free.py specific_fns/specific_setup.py


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

Header


Content

Posted by edward on April 07, 2006 - 08:00:
Author: bugman
Date: Fri Apr  7 08:00:21 2006
New Revision: 2454

URL: http://svn.gna.org/viewcvs/relax?rev=2454&view=rev
Log:
The creation of a framework for the generation of Molmol macros.

A large number of changes and additions have been made including:

The user function 'molmol.write()' has been created.

A number of functions in the generic molmol code have been renamed.  These 
are 'open_pipe' to
'pipe_open', 'pipe_open' to 'pipe_open_test', and 'write' to 'pipe_write'.

The functions 'self.write()' and 'self.create_macro()' have been added to 
'generic_fns/molmol.py'.
The first function calls the second which returns an array of Molmol 
commands.  The point of
splitting the functions is so in the future 'self.exec_macro()' can be added 
to pipe the command
directly into Molmol.

The two functions 'self.molmol_macro()' and 'self.molmol_macro_classic()' 
have been added to the
model-free specific code.  The second function currently returns a dummy 
array so that the resultant
macro is useless.  The first function is returned by the specific_setup.py 
code.

A new error class called 'RelaxStyleError' has been created.  This error is 
to be called anytime an
argument called 'style' is unrecognised.


Modified:
    1.2/errors.py
    1.2/generic_fns/molmol.py
    1.2/prompt/molmol.py
    1.2/specific_fns/model_free.py
    1.2/specific_fns/specific_setup.py

Modified: 1.2/errors.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/errors.py?rev=2454&r1=2453&r2=2454&view=diff
==============================================================================
--- 1.2/errors.py (original)
+++ 1.2/errors.py Fri Apr  7 08:00:21 2006
@@ -432,3 +432,11 @@
         def __init__(self, run):
             self.text = "Simulations for the run " + `run` + " have not been 
setup."
 
+
+    # Style errors.
+    ###############
+
+    # Unknown style.
+    class RelaxStyleError(BaseError):
+        def __init__(self, style):
+            self.text = "The style " + `style` + " is unknown."

Modified: 1.2/generic_fns/molmol.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/generic_fns/molmol.py?rev=2454&r1=2453&r2=2454&view=diff
==============================================================================
--- 1.2/generic_fns/molmol.py (original)
+++ 1.2/generic_fns/molmol.py Fri Apr  7 08:00:21 2006
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2004 Edward d'Auvergne                                       
 #
+# Copyright (C) 2004, 2006 Edward d'Auvergne                                 
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -39,24 +39,17 @@
         self.command_history = ""
 
 
-    def open_pipe(self):
-        """Function for opening a Molmol pipe."""
+    def create_macro(self):
+        """Function for creating an array of Molmol commands."""
 
-        # Open the Molmol pipe.
-        self.relax.data.molmol = popen("molmol -f -", 'w', 0)
+        # Function type.
+        self.function_type = 
self.relax.data.run_types[self.relax.data.run_names.index(self.run)]
 
-        # Execute the command history.
-        if len(self.command_history) > 0:
-            self.write(self.command_history, store_command=0)
-            return
+        # Specific Molmol macro creation function.
+        molmol_macro = self.relax.specific_setup.setup('molmol_macro', 
self.function_type)
 
-        # Test if the PDB file has been loaded.
-        if hasattr(self.relax.data, 'pdb'):
-            self.open_pdb()
-
-        # Run InitAll to remove everything from molmol.
-        else:
-            self.write("InitAll yes")
+        # Get the macro.
+        self.commands = molmol_macro(self.run, self.data_type, self.style)
 
 
     def open_pdb(self, run=None):
@@ -67,17 +60,37 @@
             self.run = run
 
         # Test if the pipe is open.
-        if not self.pipe_open():
+        if not self.pipe_open_test():
             return
 
         # Run InitAll to remove everything from molmol.
-        self.write("InitAll yes")
+        self.pipe_write("InitAll yes")
 
         # Open the PDB.
-        self.write("ReadPdb " + self.relax.data.pdb[self.run].file_name)
+        self.pipe_write("ReadPdb " + self.relax.data.pdb[self.run].file_name)
 
 
     def pipe_open(self):
+        """Function for opening a Molmol pipe."""
+
+        # Open the Molmol pipe.
+        self.relax.data.molmol = popen("molmol -f -", 'w', 0)
+
+        # Execute the command history.
+        if len(self.command_history) > 0:
+            self.pipe_write(self.command_history, store_command=0)
+            return
+
+        # Test if the PDB file has been loaded.
+        if hasattr(self.relax.data, 'pdb'):
+            self.open_pdb()
+
+        # Run InitAll to remove everything from molmol.
+        else:
+            self.pipe_write("InitAll yes")
+
+
+    def pipe_open_test(self):
         """Function for testing if the Molmol pipe is open."""
 
         # Test if a pipe has been opened.
@@ -86,12 +99,30 @@
 
         # Test if the pipe has been broken.
         try:
-            self.relax.data.molmol.write('\n')
+            self.relax.data.molmol.pipe_write('\n')
         except IOError:
             return 0
 
         # The pipe is open.
         return 1
+
+
+    def pipe_write(self, command=None, store_command=1):
+        """Function for writing to the Molmol pipe.
+
+        This function is also used to execute a user supplied Molmol command.
+        """
+
+        # Reopen the pipe if needed.
+        if not self.pipe_open_test():
+            self.pipe_open()
+
+        # Write the command to the pipe.
+        self.relax.data.molmol.pipe_write(command + '\n')
+
+        # Place the command in the command history.
+        if store_command:
+            self.command_history = self.command_history + command + "\n"
 
 
     def view(self, run=None):
@@ -101,25 +132,43 @@
         self.run = run
 
         # Open a Molmol pipe.
-        if self.pipe_open():
+        if self.pipe_open_test():
             raise RelaxError, "The Molmol pipe already exists."
         else:
-            self.open_pipe()
+            self.pipe_open()
 
 
-    def write(self, command=None, store_command=1):
-        """Function for writing to the Molmol pipe.
+    def write(self, run=None, data_type=None, style="classic", file=None, 
dir=None, force=0):
+        """Function for creating a Molmol macro."""
 
-        This function is also used to execute a user supplied Molmol command.
-        """
+        # Arguments.
+        self.run = run
+        self.data_type = data_type
+        self.style = style
 
-        # Reopen the pipe if needed.
-        if not self.pipe_open():
-            self.open_pipe()
+        # Test if the run exists.
+        if not self.run in self.relax.data.run_names:
+            raise RelaxNoRunError, self.run
 
-        # Write the command to the pipe.
-        self.relax.data.molmol.write(command + '\n')
+        # Test if the sequence data is loaded.
+        if not self.relax.data.res.has_key(self.run):
+            raise RelaxNoSequenceError, self.run
 
-        # Place the command in the command history.
-        if store_command:
-            self.command_history = self.command_history + command + "\n"
+        # Create the macro.
+        self.create_macro()
+
+        # File name.
+        if file == None:
+            file = data_type + '.mac'
+
+        # Open the file for writing.
+        file = self.relax.IO.open_write_file(file, dir, force)
+
+        # Loop over the commands and write them.
+        for command in self.commands:
+            file.write(command + "\n")
+
+        # Close the file.
+        file.close()
+
+

Modified: 1.2/prompt/molmol.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/prompt/molmol.py?rev=2454&r1=2453&r2=2454&view=diff
==============================================================================
--- 1.2/prompt/molmol.py (original)
+++ 1.2/prompt/molmol.py Fri Apr  7 08:00:21 2006
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2004 Edward d'Auvergne                                       
 #
+# Copyright (C) 2004, 2006 Edward d'Auvergne                                 
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -22,7 +22,12 @@
 
 import sys
 
+from doc_string import regexp_doc
 import help
+from generic_fns.minimise import Minimise
+from specific_fns.model_free import Model_free
+from specific_fns.jw_mapping import Jw_mapping
+from specific_fns.noe import Noe
 
 
 class Molmol:
@@ -101,3 +106,109 @@
 
         # Execute the functional code.
         self.__relax__.generic.molmol.view(run=run)
+
+
+    def write(self, run=None, data_type=None, style="classic", file=None, 
dir='molmol', force=0):
+        """Function for creating Molmol macros.
+
+        Keyword Arguments
+        ~~~~~~~~~~~~~~~~~
+
+        run:  The name of the run.
+
+        data_type:  The data type to map to the structure.
+
+        style:  The style of the macro.
+
+        file:  The name of the file.
+
+        dir:  The directory name.
+
+        force:  A flag which, if set to 1, will cause the file to be 
overwritten.
+
+
+        Description
+        ~~~~~~~~~~~
+
+        This function allows residues specific values to be mapped to a 
structure through the
+        creation of a Molmol '*.mac' macro which can be executed in Molmol 
by clicking on 'File,
+        Macro, Execute User...'.  Currently only the 'classic' style, which 
is described below, is
+        availible.
+
+
+        Classic style
+        ~~~~~~~~~~~~~
+
+        Creator:  Edward d'Auvergne
+
+        Argument string:  "classic"
+
+        Description:  The classic style draws the backbone of the protein in 
'neon' style.  Rather
+        than colouring the amino acids to which the NH bond belongs, the 
three covalent bonds of the
+        petide bond from Ca to Ca to which the NH bond belongs is coloured.
+
+        Supported data types:
+        Model-free:  S2, te, Rex.
+        
+
+
+        Examples
+        ~~~~~~~~
+
+        To create a Molmol macro mapping the order parameter values, S2, of 
the run 'final' onto the
+        structure using the classic style, type:
+
+        relax> molmol.write('final', 'S2')
+        relax> molmol.write('final', data_type='S2')
+        relax> molmol.write('final', data_type='S2', style="classic", 
file='s2.mac', dir='molmol')
+        """
+
+        # Function intro text.
+        if self.__relax__.interpreter.intro:
+            text = sys.ps3 + "molmol.write("
+            text = text + "run=" + `run`
+            text = text + ", data_type=" + `data_type`
+            text = text + ", style=" + `style`
+            text = text + ", file=" + `file`
+            text = text + ", dir=" + `dir`
+            text = text + ", force=" + `force` + ")"
+            print text
+
+        # The run name.
+        if type(run) != str:
+            raise RelaxStrError, ('run', run)
+
+        # Data type for mapping to the structure.
+        if type(data_type) != str:
+            raise RelaxStrError, ('data type', data_type)
+
+        # The style.
+        if type(style) != str:
+            raise RelaxStrError, ('style', style)
+
+        # File.
+        if file != None and type(file) != str:
+            raise RelaxStrError, ('file name', file)
+
+        # Directory.
+        if dir != None and type(dir) != str:
+            raise RelaxNoneStrError, ('directory name', dir)
+
+        # The force flag.
+        if type(force) != int or (force != 0 and force != 1):
+            raise RelaxBinError, ('force flag', force)
+
+        # Execute the functional code.
+        self.__relax__.generic.molmol.write(run=run, data_type=data_type, 
style=style, file=file, dir=dir, force=force)
+
+
+
+    # Docstring modification.
+    #########################
+
+    # Write function.
+    write.__doc__ = write.__doc__ + "\n\n" + regexp_doc() + "\n"
+    write.__doc__ = write.__doc__ + Minimise.return_data_name.__doc__ + 
"\n\n"
+    write.__doc__ = write.__doc__ + Model_free.return_data_name.__doc__ + 
"\n\n"
+    write.__doc__ = write.__doc__ + Jw_mapping.return_data_name.__doc__ + 
"\n\n"
+    write.__doc__ = write.__doc__ + Noe.return_data_name.__doc__ + "\n"

Modified: 1.2/specific_fns/model_free.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/specific_fns/model_free.py?rev=2454&r1=2453&r2=2454&view=diff
==============================================================================
--- 1.2/specific_fns/model_free.py (original)
+++ 1.2/specific_fns/model_free.py Fri Apr  7 08:00:21 2006
@@ -2598,6 +2598,28 @@
             return 1
 
 
+    def molmol_macro(self, run, data_type, style):
+        """Function for creating Molmol macros of the model-free 
parameters."""
+
+        # Arguments.
+        self.run = run
+
+        # The classic style.
+        if style == 'classic':
+            return self.molmol_macro_classic(data_type)
+
+        # Unknown style.
+        else:
+            raise RelaxStyleError, style
+
+
+    def molmol_macro_classic(self, data_type):
+        """Create and return an array of Molmol commands in the classic 
style."""
+
+        # Dummy array.
+        return ["InitAll yes"]
+
+
     def read_columnar_col_numbers(self, header):
         """Function for sorting the column numbers from the columnar 
formatted results file."""
 
@@ -4283,7 +4305,7 @@
 
         # Create the data structure.
         self.relax.data.res[run][i].relax_sim_data = sim_data
-        
+
 
     def sim_return_chi2(self, run, instance):
         """Function for returning the array of simulation chi-squared 
values."""

Modified: 1.2/specific_fns/specific_setup.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/specific_fns/specific_setup.py?rev=2454&r1=2453&r2=2454&view=diff
==============================================================================
--- 1.2/specific_fns/specific_setup.py (original)
+++ 1.2/specific_fns/specific_setup.py Fri Apr  7 08:00:21 2006
@@ -233,6 +233,10 @@
         # Model statistics.
         if self.eqi == 'model_stats':
             return self.relax.specific.model_free.model_statistics
+
+        # Molmol macro creation.
+        if self.eqi == 'molmol_macro':
+            return self.relax.specific.model_free.molmol_macro
 
         # Number of instances.
         if self.eqi == 'num_instances':




Related Messages


Powered by MHonArc, Updated Fri Apr 07 09:00:07 2006