Package schrodinger :: Package application :: Package macromodel :: Module utils :: Class SbcUtil
[hide private]
[frames] | no frames]

Class SbcUtil

A class for writing substructure/constraint files to accompany jobname.com.

MacroModel has different ways to define freely moving, restrained and constrained atoms. A good understanding of the SUBS/FXAT behavior is often essential; see the MacroModel Reference Manual for more details. Below are a few examples of some common idioms.

This class now support ASL2 with half-width flat-bottomed restraint potential. If self.use_flat_bottom_asl2 is True, then the ASL2 arguments are formatted thus:

   ASL2 arg1 = Flat-bottom width, in units of tenths of an angstrom.
   ASL2 arg2 = Force constant.
   ASL2 arg3 = Atom selection language string

otherwise, ASL2 argument are formated as:

   ASL2 arg1 = Force constant. 
   ASL2 arg2 = Atom selection language string

API examples:

   # Example 1 ############################################################
   # Writing a sbc file to restrain atoms during a minimization with ASL2.

   # Write com file instructions for a simple geometry optimization.
   # The ComUtil instance is configured such that it will write the
   # SUBS opcode in the com file.
   import schrodinger.application.macromodel.utils as mmodutils
   mcu = mmodutils.ComUtil(subs=True)
   com_file = mcu.mini("example_1.mae")
   # MacroModel requires that the sbc file name match the input
   # structure file, not the com file.
   sbc_file = 'example_1.sbc' 

   # Write sbc file that will modify the geometry optimization such that
   # all atoms are harmonically restrained about their starting coordinates.
   sbu = mmodutils.SbcUtil()
   sbu.ASL2[1] = 200 # force constant for Cartesian restraints.
   sbu.ASL2[2] = 'mol.n 1' # ASL identifying the restrained atoms.
   sbu_args = [sbc_file, 'ASL2']
   sbu.writeSbcFile(sbu_args)


   # Example 2 ############################################################
   # Writing a sbc file to perform a conformation search on part of a
   # structure with ASL1/ASL2.

   # Write com file instructions for a simple conformation search.
   # The ComUtil instance is configured such that it will write the
   # SUBS opcode in the com file.
   import schrodinger.application.macromodel.utils as mmodutils
   mcu = mmodutils.ComUtil(subs=True)
   mcu.MCMM[1] = 100 # Short test search.
   com_file = mcu.mcmm("example_2.mae")
   # MacroModel requires that the sbc file name match the input
   # structure file, not the com file.
   sbc_file = "example_2.sbc" 

   # Write an sbc file that will modify the search such that
   # only sidechain atoms are assigned search parameters and sampled.
   sbu = mmodutils.SbcUtil()
   sbu.ASL1[1] = 0 # Add the substructure atoms (set up for search).
   sbu.ASL1[2] = 'sidechain' # Substructure atoms (set up for search).

   sbu.ASL2[1] = 250 # Restraint's harmonic force constant.
   sbu.ASL2[2] = 'not sidechain' # The restrained atoms. 
   sbu_args = [sbc_file, 'ASL1', 'ASL2']
   sbu.writeSbcFile(sbu_args)


   # Example 3 ############################################################
   # Writing a sbc file to restrain/constrain part of the structure
   # with SUBS/FXAT during a simple minimization. Here, the input
   # structure is a ligand-receptor complex where the ligand has
   # residue name MTW. The ligand will be freely optimized within the
   # context of the receptor. The side-chain atoms will be fixed
   # (restrained with a flat-bottom potential, 0.1 angstrom half-width)
   # and a ~3 angstrom shell of nearby atoms will be frozen
   # (constrained). All other atoms are ignored.

   # Write com file instructions for a simple geometry optimization.
   # The ComUtil instance is configured such that it will write the
   # SUBS opcode in the com file.
   import schrodinger.application.macromodel.utils as mmodutils
   import schrodinger.structure as structure
   import schrodinger.structutils.analyze as analyze
   mcu = mmodutils.ComUtil(subs=True)
   com_file = mcu.mini("example_3.mae")
   sbc_file = "example_3.sbc" 

   # Identify the atoms to optimize, restrain and constrain. All other
   # atoms are ignored.
   st = structure.StructureReader("example_3.mae").next()
   ligand_atoms = analyze.evaluate_asl(st, 'res.pt MTW')
   binding_site_atoms = analyze.evaluate_asl(
       st,
       'fillres (sidechain and within 5 res.pt MTW)'
   )
   nearby_atoms = analyze.evaluate_asl(
       st,
       'not (res.pt MTW or fillres (sidechain and within 5 res.pt MTW)) and within 10 res.pt MTW'
   )

   # Assign the atoms to SUBS and FXAT commands.
   sbu = mmodutils.SbcUtil()
   sbu_args = [sbc_file]
   sbu_args.extend(sbu.setSubs(ligand_atoms))
   sbu_args.extend(
       sbu.setFixed(
           binding_site_atoms,
           force_constant=500,
           half_width=1
       )
   )
   sbu_args.extend(sbu.setFrozen(nearby_atoms))
   sbu.writeSbcFile(sbu_args)


   # Example 4 ############################################################
   # Writing a sbc file to restrain/constrain part of the structure
   # with ASL1/ASL2, where the input is a series of non-conformers.
   # Here, the structure file contains a series of non-conformer
   # polypeptides. The side-chains will be freely optimized and the
   # backbone will be restrained. Note well, READ arg1=-1 tells
   # MacroModel to evaluate the sbc for each input structure; a
   # requirement since the input are non-conformers.

   # Write com file instructions for a geometry optimization on a
   # series of structures. The ComUtil instance is configured such
   # that it will write the SUBS opcode in the com file.
   import schrodinger.application.macromodel.utils as mmodutils
   mcu = mmodutils.ComUtil(subs=True)
   mcu.READ[1] = -1 # re-evaluate substructure information.
   com_file = mcu.mini("example_4.mae")
   sbc_file = "example_4.sbc"

   # Assign the ASL1/2 commands and write the file.
   sbu = mmodutils.SbcUtil()
   sbu.ASL1[1] = 0 # Add the substructure atoms (set up for search).
   sbu.ASL1[2] = 'sidechain' # Substructure atoms (set up for search).
   sbu.ASL2[1] = 200 # Restraint's harmonic force constant.
   sbu.ASL2[2] = 'not sidechain' # The restrained atoms. 
   sbu_args = [sbc_file, 'ASL1', 'ASL2']
   sbu.writeSbcFile(sbu_args)


   # Example 5 ############################################################
   # Writing a sbc file to restrain part of the structure with
   # ASL1/ASL2 and flat-bottom restraints. Here, the structure file
   # contains a series of non-conformer polypeptides. The side-chains
   # will be freely optimized and the backbone will be restrained.
   # Note well, READ arg1=-1 which tells MacroModel to evaluate the sbc
   # for each input structure; a requirement since the input are
   # non-conformers.

   # Write com file instructions for a geometry optimization on a
   # series of structures. The ComUtil instance is configured such
   # that it will write the SUBS opcode in the com file.
   import schrodinger.application.macromodel.utils as mmodutils
   mcu = mmodutils.ComUtil(subs=True)
   mcu.READ[1] = -1 # re-evaluate substructure information.
   com_file = mcu.mini("example_5.mae")
   sbc_file = "example_5.sbc"

   # Assign the ASL1/2 commands and write the file.
   sbu = mmodutils.SbcUtil(use_flat_bottom_asl2=True)
   sbu.ASL1[1] = 0 # Add the substructure atoms (set up for search).
   sbu.ASL1[2] = 'sidechain' # Substructure atoms (set up for search).
   sbu.ASL2[1] = 5 # half-width, 0.5 angstroms. 
   sbu.ASL2[2] = 200.0 # restrain 200 kJ/mol*A^2.
   sbu.ASL2[3] = 'not sidechain' # The restrained atoms. 
   sbu_args = [sbc_file, 'ASL1', 'ASL2']
   sbu.writeSbcFile(sbu_args)


   # Example 6 ############################################################
   # Writing a sbc file to restrain atoms during a minimization
   # with ASL2, confirming backwards compatible support for
   # determining a suitable sbc file name.

   # Write com file instructions for a simple geometry optimization.
   # The ComUtil instance is configured such that it will write the
   # SUBS opcode in the com file.
   import schrodinger.application.macromodel.utils as mmodutils
   mcu = mmodutils.ComUtil(subs=True)
   com_file = mcu.mini("example_6.mae", "example_6_test.com")

   # Write sbc file that will modify the geometry optimization such that
   # all atoms are harmonically restrained about their starting coordinates.
   sbu = mmodutils.SbcUtil()
   sbu.ASL2[1] = 200 # force constant for Cartesian restraints.
   sbu.ASL2[2] = 'mol.n 1' # ASL identifying the restrained atoms.
   sbu_args = [com_file, 'ASL2']

   # MacroModel requires that the sbc file name match the input
   # structure file, not the com file.  The method expects a
   # sbc file name as the first argument, but for backwards
   # compatibility, supports .com extensions. 
   sbc_file = sbu.writeSbcFile(sbu_args)
Instance Methods [hide private]
 
__init__(self, use_flat_bottom_asl2=False)
 
writeSbcFile(self, sbc_args=[])
Writes a sbc file for the list of opcodes, and returns the name of the written sbc file.
list
setSubs(self, subs_list)
Returns: List of 'SUBS' strings after assiging all atom indexed in subs_list to the self.SUBS dict, .
list
setFixed(self, fixed_list=[], force_constant=200, half_width=0)
Returns: List of 'FXAT' strings after assiging all atom indexed in fixed_list to the self.FXAT dict.
list
setFrozen(self, frozen_list=[])
Returns: List of 'FXAT' strings after assiging all atom indexed in frozen_list to the self.FXAT dict, .
 
getOpcdArgs(self, opcd='')
The arguments come from the hash data members, any unknown or unassigned values default to 0 or 0.0.
 
_formatOpcdStr(self, args)
 
_formatSbcAsl1Str(self, args)
 
_getSbcAsl2Str(self, args)
 
setOpcdArgs(self, opcd='', arg1=0, arg2=0, arg3=0, arg4=0, arg5=0.0, arg6=0.0, arg7=0.0, arg8=0.0)
This method returns True after adding the passed values to the desired opcd dictionary.
Method Details [hide private]

writeSbcFile(self, sbc_args=[])

 

Writes a sbc file for the list of opcodes, and returns the name
of the written sbc file.

@param sbc_args:
    List of arguments to serialize.  The first element should be
    the file name to write, e.g. 'jobname.sbc', where the sbc
    file name corresponds to the input structure file name not
    the input com file name.  The second and subsequent elements
    should be OPCD strings.
@type sbc_args:
    list

@raises:
    ValueError if the first element doesn't end with .sbc and
    an appropriate sbc file name can't be determined.

The arguments for the OPCDs are looked up in turn, evaluating
the next eight list elements for the specific OPCD argument
list, each time the OPCD is encountered.  See getOpcdArgs()
and __init__() for more information about default arguments.
For backwards compatibility, the first argument may also be a
'.com', which will write basename.sbc if the com file can't
be read, but will otherwise inspect the com file for the input
structure file name and construct a suitable sbc file name.

setSubs(self, subs_list)

 
Parameters:
  • subs_list (list) - List of atom indexes
Returns: list
List of 'SUBS' strings after assiging all atom indexed in subs_list to the self.SUBS dict, . This is a simple wrapper for setOpcdArgs() to conveniently set a large number of atoms at once. Assigned SUBS have args5-8 set to 0.0 (the default).

setFixed(self, fixed_list=[], force_constant=200, half_width=0)

 
Parameters:
  • fixed_list (list) - List of atom indexes
  • force_constant (float) - Restraining force constant, typically in units of kJ/mol*A^2. Default is 200.
  • half_width (integer) - Half-width of the flat-bottom restraint potential, in tenths of an angstrom units. Default is 0.
Returns: list
List of 'FXAT' strings after assiging all atom indexed in fixed_list to the self.FXAT dict. This is a simple wrapper for setOpcdArgs() to conveniently set a large number of atoms at once. Assigned FXATs have arg5 = force_constant, and arg6 = half_width

setFrozen(self, frozen_list=[])

 
Parameters:
  • frozen_list (list) - List of atom indexes
Returns: list
List of 'FXAT' strings after assiging all atom indexed in frozen_list to the self.FXAT dict, . This is a simple wrapper for setOpcdArgs() to conveniently set a large number of atoms at once. Assigned FXATs have arg5 = -1, to freeze (constrain) the atoms in place.

getOpcdArgs(self, opcd='')

 

The arguments come from the hash data members, any unknown or unassigned values default to 0 or 0.0. You may customize the self hash arguments to your heart's content prior to invoking the method to get the exact behavior you want. The 'OPCD' lookup requires the passed argument to be a key for the hash, i.e. uppercase with no whitespace. The array of arg values are numbers, not strings.

This method keeps count of the number of times an OPCD is called and automatically increments the array of args for the passed OPCD. The first call for a given OPCD uses self['OPCD'] arg slices 1-8, the next call for that OPCD uses slices 9-16, the next 17-24, and so on. writeSbcFile() zeros the count after the com or sbc file is serialized.

Returns a formatted string of OPCD and arguments for the passed OPCD string.

Parameters:
  • opcd (string) - MacroModel operation code.

setOpcdArgs(self, opcd='', arg1=0, arg2=0, arg3=0, arg4=0, arg5=0.0, arg6=0.0, arg7=0.0, arg8=0.0)

 

This method returns True after adding the passed values to the desired opcd dictionary.

The dictionary is selected by the first parameter, which is required. The rest of the parameters are mapped to the next eight argument indices in the dictionary. Unspecified values default to 0 or 0.0.

This method determines the highest existing index (numeric hash key), and then assigns the passed args to the next available slots. You may want to first blank the dictionary with the appropriate call of self['OPCD'].clear().

Assumming the dictionary has has been cleared, the first 'set' of a given OPCD assigns self['OPCD'] arg indices 1-8, the next call for that OPCD defines indices 9-16, the next 17-24, and so on.