schrodinger.application.glide.glide module

Classes for creating Grid Generation and Ligand Docking DICE (Impact) input files from user-friendly keyword/value pairs.

The classes use the mm.mmim* wrappers to convert the keywords and values into the actual DICE input files.

Job parameters are specified by passing a dictionary of keyword/value pairs to the class initialization method. In addition, some parameters, such as constraints, can be specified by calling class methods.

Calling the writeSimplified() method will create the input file that can be passed to $SCHRODINGER/glide. The value of the JOBNAME keyword will be used as the base name for the input file.

For a full list of keywords accepted by the Gridgen and Dock classes, respectively, see the output of

$SCHRODINGER/glide -gridgen-keywords
$SCHRODINGER/glide -docking-keywords

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.application.glide.glide.Grid(grid_file)

Bases: object

Class representing the user selected grid file.

__init__(grid_file)
isValid()

Whether the specified grid file is valid.

class schrodinger.application.glide.glide.Constraint(label, constype)

Bases: object

Class defining a docking constraint in the receptor.

__init__(label, constype)
property name

User-visible constraint name, as it appears in UI and in Glide input files.

type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.DonorConstraint(label, atoms=None)

Bases: schrodinger.application.glide.glide._HBondConstraint

H-Bond constraint that was specified as a receptor donor atom. A ligand must have an ACCEPTOR group that is making an interaction with this atom to satisfy this constraint.

__init__(label, atoms=None)
atom()
atoms()
keyword = 'HBOND_CONSTRAINTS'
property name

User-visible constraint name, as it appears in UI and in Glide input files.

sifValue()
type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.AcceptorConstraint(label, atoms=None)

Bases: schrodinger.application.glide.glide._HBondConstraint

H-Bond constraint that was specified as a receptor acceptor atom. A ligand must have a DONOR group that is making an interaction with this atom to satisfy this constraint.

__init__(label, atoms=None)
atom()
atoms()
keyword = 'HBOND_CONSTRAINTS'
property name

User-visible constraint name, as it appears in UI and in Glide input files.

sifValue()
type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.MetalConstraint(label, atoms=None)

Bases: schrodinger.application.glide.glide.Constraint

This constraint was specified as a metal receptor atom. A ligand must interact with this metal atom to satisfy this constraint.

keyword = 'METAL_CONSTRAINTS'
__init__(label, atoms=None)
atoms()
atom()
sifValue()
property name

User-visible constraint name, as it appears in UI and in Glide input files.

type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.PositionalConstraint(label, x=None, y=None, z=None, radius=None)

Bases: schrodinger.application.glide.glide.Constraint

keyword = 'POSIT_CONSTRAINTS'
__init__(label, x=None, y=None, z=None, radius=None)
sifValue()
property name

User-visible constraint name, as it appears in UI and in Glide input files.

type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.NOEConstraint(label, x=None, y=None, z=None, rmin=None, rmax=None)

Bases: schrodinger.application.glide.glide.Constraint

keyword = 'NOE_CONSTRAINTS'
__init__(label, x=None, y=None, z=None, rmin=None, rmax=None)
sifValue()
property name

User-visible constraint name, as it appears in UI and in Glide input files.

type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.MetCoordConstraint(label, xmetc, ymetc, zmetc, rmetc)

Bases: schrodinger.application.glide.glide.Constraint

keyword = 'METCOORD_CONSTRAINTS'
sites_keyword = 'METCOORD_SITES'
__init__(label, xmetc, ymetc, zmetc, rmetc)
sifValue()
siteSifValue()
property name

User-visible constraint name, as it appears in UI and in Glide input files.

type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.HydrophobicConstraint(label)

Bases: schrodinger.application.glide.glide.Constraint

__init__(label)
property name

User-visible constraint name, as it appears in UI and in Glide input files.

type()

Return the type of the (receptor) constraint as a user-friendly string. Possible return values:

  • ‘Hydrophobic’

  • ‘H-bond donor’

  • ‘H-bond acceptor’

  • ‘Metal’

  • ‘Positional’

  • ‘NOE’

  • ‘Metal coordination’

class schrodinger.application.glide.glide.FeaturePattern(smarts, atoms, exclude=False, nfill=None)

Bases: object

Class defining a constraint feature pattern.

__init__(smarts, atoms, exclude=False, nfill=None)
class schrodinger.application.glide.glide.Feature(patterns=None)

Bases: object

A list of FeaturePattern objects. Each pattern has these properties: smarts, atoms, exclude.

__init__(patterns=None)
Parameters

patterns (list) – List of patterns associated with this feature. A shallow copy of the patterns list will be made for the new Feature object.

class schrodinger.application.glide.glide.ConstraintGroup(parent, constraints=None, nrequired=- 1)

Bases: object

Class defining a constraint group.

__init__(parent, constraints=None, nrequired=- 1)
addConstraint(label)
setup(cons_labels, feature_sets)
cleanup()

Free the memory associated with this group

class schrodinger.application.glide.glide.GlideJob(jobtype=None, specs=None, keywords=None, createhandle=False)

Bases: schrodinger.application.inputconfig.InputConfig

Class for writing Glide input files - either Gridgen or Docking. The keywords passed are used to set MMIM directly with no processing.

__init__(jobtype=None, specs=None, keywords=None, createhandle=False)

Specify a dictionary of keywords, where the key is the short keyword name and the value is what is should be set to. For indexed keywords, the value needs to be a list. It is also possible to specify a file path to a simplified input file that contains the keywords.

validateValues(*args, **kwargs)

Validate the keywords against the spec. Unlike the parent implementation, raise a ValueError if any unknown keywords are present.

get(key, default=None)

A version of get that doesn’t bypass string interpolation.

getAllowedRange(key)

Will return a tuple of (min, max) for the allowed range of value. Either or both of these values may be None.

Returns

The allowed min/max range.

Return type

Tuple of 2 ints/floats.

cleanup()

Clean up constraints objects.

writeSimplified(filename=None, yesno=False)

Writes a simplified input file to “<jobname>.inp”. This input file needs to be run via $SCHRODINGER/glide.

applyContextDependentDefaults()

Apply context-dependent defaults for a Glide job. It modifies the job object, but marks the modified keywords as “default” so they won’t be written by writeSimplified().

checkConflicts()

Check for invalid keyword combinations. Raises a ValueError if any are found.

setupJson(jsdict)

Additional setup to do before writing a JSON file. Base implementation does nothing. This method is expected not to modify ‘self’, but only jsdict, which is the dictionary of keywords that ultimately will be written to the JSON file.

checkForceFieldLicense(jsdict)

If we are using the default forcefield (OPLS3) and don’t have an OPLS license, fall back to using OPLS_2005.

compileDict()

Return a “compiled” dict with _all_ the keywords, including the ones with default values, after doing validation and applying context-dependent defaults.

writeJSON(filename=None)

Write the keywords as a JSON representation. Unlike writeSimplified, this includes the values for all the keywords, not only the non-default ones.

__contains__(key, /)

True if the dictionary has the specified key, else False.

__len__()

Return len(self).

as_bool(key)

Accepts a key as input. The corresponding value must be a string or the objects (True or 1) or (False or 0). We allow 0 and 1 to retain compatibility with Python 2.2.

If the string is one of True, On, Yes, or 1 it returns True.

If the string is one of False, Off, No, or 0 it returns False.

as_bool is not case sensitive.

Any other input will raise a ValueError.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_bool('a')
Traceback (most recent call last):
ValueError: Value "fish" is neither True nor False
>>> a['b'] = 'True'
>>> a.as_bool('b')
1
>>> a['b'] = 'off'
>>> a.as_bool('b')
0
as_float(key)

A convenience method which coerces the specified value to a float.

If the value is an invalid literal for float, a ValueError will be raised.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_float('a')  
Traceback (most recent call last):
ValueError: invalid literal for float(): fish
>>> a['b'] = '1'
>>> a.as_float('b')
1.0
>>> a['b'] = '3.2'
>>> a.as_float('b')  
3.2...
as_int(key)

A convenience method which coerces the specified value to an integer.

If the value is an invalid literal for int, a ValueError will be raised.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_int('a')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: 'fish'
>>> a['b'] = '1'
>>> a.as_int('b')
1
>>> a['b'] = '3.2'
>>> a.as_int('b')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '3.2'
as_list(key)

A convenience method which fetches the specified value, guaranteeing that it is a list.

>>> a = ConfigObj()
>>> a['a'] = 1
>>> a.as_list('a')
[1]
>>> a['a'] = (1,)
>>> a.as_list('a')
[1]
>>> a['a'] = [1]
>>> a.as_list('a')
[1]
clear()

A version of clear that also affects scalars/sections Also clears comments and configspec.

Leaves other attributes alone :

depth/main/parent are not affected

copy() a shallow copy of D
dict()

Return a deepcopy of self as a dictionary.

All members that are Section instances are recursively turned to ordinary dictionaries - by calling their dict method.

>>> n = a.dict()
>>> n == a
1
>>> n is a
0
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

getSpecsString()

Return a string of specifications. One keywords per line. Raises ValueError if this class has no specifications.

items() list of D’s (key, value) pairs, as 2-tuples
iteritems() an iterator over the (key, value) items of D
iterkeys() an iterator over the keys of D
itervalues() an iterator over the values of D
keys() list of D’s keys
merge(indict)

A recursive update - useful for merging config files.

>>> a = '''[section1]
...     option1 = True
...     [[subsection]]
...     more_options = False
...     # end of file'''.splitlines()
>>> b = '''# File is user.ini
...     [section1]
...     option1 = False
...     # end of file'''.splitlines()
>>> c1 = ConfigObj(b)
>>> c2 = ConfigObj(a)
>>> c2.merge(c1)
>>> c2
ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}})
pop(key, default=<object object>)

‘D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised’

popitem()

Pops the first (key,val)

printout()

Print all keywords of this instance to stdout.

This method is meant for debugging purposes.

reload()

Reload a ConfigObj from file.

This method raises a ReloadError if the ConfigObj doesn’t have a filename attribute pointing to a file.

rename(oldkey, newkey)

Change a keyname to another, without changing position in sequence.

Implemented so that transformations can be made on keys, as well as on values. (used by encode and decode)

Also renames comments.

reset()

Clear ConfigObj instance and restore to ‘freshly created’ state.

restore_default(key)

Restore (and return) default value for the specified key.

This method will only work for a ConfigObj that was created with a configspec and has been validated.

If there is no default value for this key, KeyError is raised.

restore_defaults()

Recursively restore default values to all members that have them.

This method will only work for a ConfigObj that was created with a configspec and has been validated.

It doesn’t delete or modify entries without default values.

setdefault(key, default=None)

A version of setdefault that sets sequence if appropriate.

update(indict)

A version of update that uses our __setitem__.

validate(validator, preserve_errors=False, copy=False, section=None)

Test the ConfigObj against a configspec.

It uses the validator object from validate.py.

To run validate on the current ConfigObj, call:

test = config.validate(validator)

(Normally having previously passed in the configspec when the ConfigObj was created - you can dynamically assign a dictionary of checks to the configspec attribute of a section though).

It returns True if everything passes, or a dictionary of pass/fails (True/False). If every member of a subsection passes, it will just have the value True. (It also returns False if all members fail).

In addition, it converts the values from strings to their native types if their checks pass (and stringify is set).

If preserve_errors is True (False is default) then instead of a marking a fail with a False, it will preserve the actual exception object. This can contain info about the reason for failure. For example the VdtValueTooSmallError indicates that the value supplied was too small. If a value (or section) is missing it will still be marked as False.

You must have the validate module to use preserve_errors=True.

You can then use the flatten_errors function to turn your nested results dictionary into a flattened list of failures - useful for displaying meaningful error messages.

values() list of D’s values
walk(function, raise_errors=True, call_on_sections=False, **keywargs)

Walk every member and call a function on the keyword and value.

Return a dictionary of the return values

If the function raises an exception, raise the errror unless raise_errors=False, in which case set the return value to False.

Any unrecognised keyword arguments you pass to walk, will be pased on to the function you pass in.

Note: if call_on_sections is True then - on encountering a subsection, first the function is called for the whole subsection, and then recurses into it’s members. This means your function must be able to handle strings, dictionaries and lists. This allows you to change the key of subsections as well as for ordinary members. The return value when called on the whole subsection has to be discarded.

See the encode and decode methods for examples, including functions.

caution

You can use walk to transform the names of members of a section but you mustn’t add or delete members.

>>> config = '''[XXXXsection]
... XXXXkey = XXXXvalue'''.splitlines()
>>> cfg = ConfigObj(config)
>>> cfg
ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}})
>>> def transform(section, key):
...     val = section[key]
...     newkey = key.replace('XXXX', 'CLIENT1')
...     section.rename(key, newkey)
...     if isinstance(val, (tuple, list, dict)):
...         pass
...     else:
...         val = val.replace('XXXX', 'CLIENT1')
...         section[newkey] = val
>>> cfg.walk(transform, call_on_sections=True)
{'CLIENT1section': {'CLIENT1key': None}}
>>> cfg
ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}})
write(outfile=None, section=None)

Write the current ConfigObj as a file

tekNico: FIXME: use StringIO instead of real files

>>> filename = a.filename
>>> a.filename = 'test.ini'
>>> a.write()
>>> a.filename = filename
>>> a == ConfigObj('test.ini', raise_errors=True)
1
>>> import os
>>> os.remove('test.ini')
writeInputFile(filename, ignore_none=False, yesno=False, smartsort=False)

Write the configuration to a file in the InputConfig format.

Parameters
  • filename (a file path or an open file handle) – The file to write the configuration to.

  • ignore_none (bool) – If True, keywords with a value of None will not be written to the input file.

  • yesno (bool) – If True, boolean keywords will be written as “yes” and “no”, if False, as “True” and “False”.

  • smartsort (bool) – If True, keywords that are identical except for the numbers at the end will be sorted such that “2” will go before “10”.

class schrodinger.application.glide.glide.Gridgen(keywords)

Bases: schrodinger.application.glide.glide.GlideJob

Class for writing Glide Grid Generation input files. Currently, the receptor input file for a Gridgen job (NOT created by this class) must be named “<jobname>.mae”.

__init__(keywords)

Specify a dictionary of keywords, where the key is the short keyword name and the value is what is should be set to. For indexed keywords, the value needs to be a list. It is also possible to specify a file path to a simplified input file that contains the keywords.

Constraint sites may be set via the following keywords:

HBOND_CONSTRAINTS METAL_CONSTRAINTS POSIT_CONSTRAINTS NOE_CONSTRAINTS METCOORD_CONSTRAINTS METCOORD_SITES

Parameters

keywords (dict or file path) – Either a dictionary of keywords or a simplified input file path.

Raises

RuntimeError – If no job name specified.

setupJson(jsdict)

Additional setup to do before writing a JSON file. Base implementation does nothing. This method is expected not to modify ‘self’, but only jsdict, which is the dictionary of keywords that ultimately will be written to the JSON file.

cleanup()

Free the memory associated with constraings

__contains__(key, /)

True if the dictionary has the specified key, else False.

__len__()

Return len(self).

applyContextDependentDefaults()

Apply context-dependent defaults for a Glide job. It modifies the job object, but marks the modified keywords as “default” so they won’t be written by writeSimplified().

as_bool(key)

Accepts a key as input. The corresponding value must be a string or the objects (True or 1) or (False or 0). We allow 0 and 1 to retain compatibility with Python 2.2.

If the string is one of True, On, Yes, or 1 it returns True.

If the string is one of False, Off, No, or 0 it returns False.

as_bool is not case sensitive.

Any other input will raise a ValueError.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_bool('a')
Traceback (most recent call last):
ValueError: Value "fish" is neither True nor False
>>> a['b'] = 'True'
>>> a.as_bool('b')
1
>>> a['b'] = 'off'
>>> a.as_bool('b')
0
as_float(key)

A convenience method which coerces the specified value to a float.

If the value is an invalid literal for float, a ValueError will be raised.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_float('a')  
Traceback (most recent call last):
ValueError: invalid literal for float(): fish
>>> a['b'] = '1'
>>> a.as_float('b')
1.0
>>> a['b'] = '3.2'
>>> a.as_float('b')  
3.2...
as_int(key)

A convenience method which coerces the specified value to an integer.

If the value is an invalid literal for int, a ValueError will be raised.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_int('a')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: 'fish'
>>> a['b'] = '1'
>>> a.as_int('b')
1
>>> a['b'] = '3.2'
>>> a.as_int('b')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '3.2'
as_list(key)

A convenience method which fetches the specified value, guaranteeing that it is a list.

>>> a = ConfigObj()
>>> a['a'] = 1
>>> a.as_list('a')
[1]
>>> a['a'] = (1,)
>>> a.as_list('a')
[1]
>>> a['a'] = [1]
>>> a.as_list('a')
[1]
checkConflicts()

Check for invalid keyword combinations. Raises a ValueError if any are found.

checkForceFieldLicense(jsdict)

If we are using the default forcefield (OPLS3) and don’t have an OPLS license, fall back to using OPLS_2005.

clear()

A version of clear that also affects scalars/sections Also clears comments and configspec.

Leaves other attributes alone :

depth/main/parent are not affected

compileDict()

Return a “compiled” dict with _all_ the keywords, including the ones with default values, after doing validation and applying context-dependent defaults.

copy() a shallow copy of D
dict()

Return a deepcopy of self as a dictionary.

All members that are Section instances are recursively turned to ordinary dictionaries - by calling their dict method.

>>> n = a.dict()
>>> n == a
1
>>> n is a
0
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None)

A version of get that doesn’t bypass string interpolation.

getAllowedRange(key)

Will return a tuple of (min, max) for the allowed range of value. Either or both of these values may be None.

Returns

The allowed min/max range.

Return type

Tuple of 2 ints/floats.

getSpecsString()

Return a string of specifications. One keywords per line. Raises ValueError if this class has no specifications.

items() list of D’s (key, value) pairs, as 2-tuples
iteritems() an iterator over the (key, value) items of D
iterkeys() an iterator over the keys of D
itervalues() an iterator over the values of D
keys() list of D’s keys
merge(indict)

A recursive update - useful for merging config files.

>>> a = '''[section1]
...     option1 = True
...     [[subsection]]
...     more_options = False
...     # end of file'''.splitlines()
>>> b = '''# File is user.ini
...     [section1]
...     option1 = False
...     # end of file'''.splitlines()
>>> c1 = ConfigObj(b)
>>> c2 = ConfigObj(a)
>>> c2.merge(c1)
>>> c2
ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}})
pop(key, default=<object object>)

‘D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised’

popitem()

Pops the first (key,val)

printout()

Print all keywords of this instance to stdout.

This method is meant for debugging purposes.

reload()

Reload a ConfigObj from file.

This method raises a ReloadError if the ConfigObj doesn’t have a filename attribute pointing to a file.

rename(oldkey, newkey)

Change a keyname to another, without changing position in sequence.

Implemented so that transformations can be made on keys, as well as on values. (used by encode and decode)

Also renames comments.

reset()

Clear ConfigObj instance and restore to ‘freshly created’ state.

restore_default(key)

Restore (and return) default value for the specified key.

This method will only work for a ConfigObj that was created with a configspec and has been validated.

If there is no default value for this key, KeyError is raised.

restore_defaults()

Recursively restore default values to all members that have them.

This method will only work for a ConfigObj that was created with a configspec and has been validated.

It doesn’t delete or modify entries without default values.

setdefault(key, default=None)

A version of setdefault that sets sequence if appropriate.

update(indict)

A version of update that uses our __setitem__.

validate(validator, preserve_errors=False, copy=False, section=None)

Test the ConfigObj against a configspec.

It uses the validator object from validate.py.

To run validate on the current ConfigObj, call:

test = config.validate(validator)

(Normally having previously passed in the configspec when the ConfigObj was created - you can dynamically assign a dictionary of checks to the configspec attribute of a section though).

It returns True if everything passes, or a dictionary of pass/fails (True/False). If every member of a subsection passes, it will just have the value True. (It also returns False if all members fail).

In addition, it converts the values from strings to their native types if their checks pass (and stringify is set).

If preserve_errors is True (False is default) then instead of a marking a fail with a False, it will preserve the actual exception object. This can contain info about the reason for failure. For example the VdtValueTooSmallError indicates that the value supplied was too small. If a value (or section) is missing it will still be marked as False.

You must have the validate module to use preserve_errors=True.

You can then use the flatten_errors function to turn your nested results dictionary into a flattened list of failures - useful for displaying meaningful error messages.

validateValues(*args, **kwargs)

Validate the keywords against the spec. Unlike the parent implementation, raise a ValueError if any unknown keywords are present.

values() list of D’s values
walk(function, raise_errors=True, call_on_sections=False, **keywargs)

Walk every member and call a function on the keyword and value.

Return a dictionary of the return values

If the function raises an exception, raise the errror unless raise_errors=False, in which case set the return value to False.

Any unrecognised keyword arguments you pass to walk, will be pased on to the function you pass in.

Note: if call_on_sections is True then - on encountering a subsection, first the function is called for the whole subsection, and then recurses into it’s members. This means your function must be able to handle strings, dictionaries and lists. This allows you to change the key of subsections as well as for ordinary members. The return value when called on the whole subsection has to be discarded.

See the encode and decode methods for examples, including functions.

caution

You can use walk to transform the names of members of a section but you mustn’t add or delete members.

>>> config = '''[XXXXsection]
... XXXXkey = XXXXvalue'''.splitlines()
>>> cfg = ConfigObj(config)
>>> cfg
ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}})
>>> def transform(section, key):
...     val = section[key]
...     newkey = key.replace('XXXX', 'CLIENT1')
...     section.rename(key, newkey)
...     if isinstance(val, (tuple, list, dict)):
...         pass
...     else:
...         val = val.replace('XXXX', 'CLIENT1')
...         section[newkey] = val
>>> cfg.walk(transform, call_on_sections=True)
{'CLIENT1section': {'CLIENT1key': None}}
>>> cfg
ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}})
write(outfile=None, section=None)

Write the current ConfigObj as a file

tekNico: FIXME: use StringIO instead of real files

>>> filename = a.filename
>>> a.filename = 'test.ini'
>>> a.write()
>>> a.filename = filename
>>> a == ConfigObj('test.ini', raise_errors=True)
1
>>> import os
>>> os.remove('test.ini')
writeInputFile(filename, ignore_none=False, yesno=False, smartsort=False)

Write the configuration to a file in the InputConfig format.

Parameters
  • filename (a file path or an open file handle) – The file to write the configuration to.

  • ignore_none (bool) – If True, keywords with a value of None will not be written to the input file.

  • yesno (bool) – If True, boolean keywords will be written as “yes” and “no”, if False, as “True” and “False”.

  • smartsort (bool) – If True, keywords that are identical except for the numbers at the end will be sorted such that “2” will go before “10”.

writeJSON(filename=None)

Write the keywords as a JSON representation. Unlike writeSimplified, this includes the values for all the keywords, not only the non-default ones.

writeSimplified(filename=None, yesno=False)

Writes a simplified input file to “<jobname>.inp”. This input file needs to be run via $SCHRODINGER/glide.

class schrodinger.application.glide.glide.Dock(keywords, jobtypes=None)

Bases: schrodinger.application.glide.glide.GlideJob

Class for generating Glide docking input files.

__init__(keywords, jobtypes=None)

Specify a dictionary of keywords, where the key is the short keyword name and the value is what is should be set to. For indexed keywords, the value needs to be a list. It is also possible to specify a file path to a simplified input file that contains the keywords.

Parameters

keywords (dict or file path) – Either a dictionary of keywords or a simplified input file path.

setLigRange(start, end)

Shortcut for setting the range of ligands to be read from the LIGANDFILE.

Parameters

end – If zero, means to go to the end of the file.

checkConflicts()

Check for invalid keyword combinations. Raises a ValueError if any are found.

applyContextDependentDefaults()

Apply context-dependent defaults for a Glide job. It modifies the job object, but marks the modified keywords as “default” so they won’t be written by writeSimplified().

setupJson(jsdict)

Additional setup to do before writing a JSON file. Base implementation does nothing. This method is expected not to modify ‘self’, but only jsdict, which is the dictionary of keywords that ultimately will be written to the JSON file.

readConsKeywords()

Reads the constraint keywords, parses their values, and returns them as a tuple of (cons groups, feature sets).

cleanup()

Free up the group handles

addConstraintGroup(cons_labels, nrequired)

Add a new constraint group to this Docking instance.

Parameters
  • cons_labels – A list of labels for constraints to use.

  • nrequired – Minimum number of constraints required for match (Can be ALL).

useConstraint(label)

Adds specified constraint to the first group.

Default group is #1; constraint type determined automatically.

setNRequired(nrequired)

Set the minimum number of constraints required for the first group. A value of ALL means all constraints are required.

__contains__(key, /)

True if the dictionary has the specified key, else False.

__len__()

Return len(self).

as_bool(key)

Accepts a key as input. The corresponding value must be a string or the objects (True or 1) or (False or 0). We allow 0 and 1 to retain compatibility with Python 2.2.

If the string is one of True, On, Yes, or 1 it returns True.

If the string is one of False, Off, No, or 0 it returns False.

as_bool is not case sensitive.

Any other input will raise a ValueError.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_bool('a')
Traceback (most recent call last):
ValueError: Value "fish" is neither True nor False
>>> a['b'] = 'True'
>>> a.as_bool('b')
1
>>> a['b'] = 'off'
>>> a.as_bool('b')
0
as_float(key)

A convenience method which coerces the specified value to a float.

If the value is an invalid literal for float, a ValueError will be raised.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_float('a')  
Traceback (most recent call last):
ValueError: invalid literal for float(): fish
>>> a['b'] = '1'
>>> a.as_float('b')
1.0
>>> a['b'] = '3.2'
>>> a.as_float('b')  
3.2...
as_int(key)

A convenience method which coerces the specified value to an integer.

If the value is an invalid literal for int, a ValueError will be raised.

>>> a = ConfigObj()
>>> a['a'] = 'fish'
>>> a.as_int('a')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: 'fish'
>>> a['b'] = '1'
>>> a.as_int('b')
1
>>> a['b'] = '3.2'
>>> a.as_int('b')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '3.2'
as_list(key)

A convenience method which fetches the specified value, guaranteeing that it is a list.

>>> a = ConfigObj()
>>> a['a'] = 1
>>> a.as_list('a')
[1]
>>> a['a'] = (1,)
>>> a.as_list('a')
[1]
>>> a['a'] = [1]
>>> a.as_list('a')
[1]
checkForceFieldLicense(jsdict)

If we are using the default forcefield (OPLS3) and don’t have an OPLS license, fall back to using OPLS_2005.

clear()

A version of clear that also affects scalars/sections Also clears comments and configspec.

Leaves other attributes alone :

depth/main/parent are not affected

compileDict()

Return a “compiled” dict with _all_ the keywords, including the ones with default values, after doing validation and applying context-dependent defaults.

copy() a shallow copy of D
dict()

Return a deepcopy of self as a dictionary.

All members that are Section instances are recursively turned to ordinary dictionaries - by calling their dict method.

>>> n = a.dict()
>>> n == a
1
>>> n is a
0
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None)

A version of get that doesn’t bypass string interpolation.

getAllowedRange(key)

Will return a tuple of (min, max) for the allowed range of value. Either or both of these values may be None.

Returns

The allowed min/max range.

Return type

Tuple of 2 ints/floats.

getSpecsString()

Return a string of specifications. One keywords per line. Raises ValueError if this class has no specifications.

items() list of D’s (key, value) pairs, as 2-tuples
iteritems() an iterator over the (key, value) items of D
iterkeys() an iterator over the keys of D
itervalues() an iterator over the values of D
keys() list of D’s keys
merge(indict)

A recursive update - useful for merging config files.

>>> a = '''[section1]
...     option1 = True
...     [[subsection]]
...     more_options = False
...     # end of file'''.splitlines()
>>> b = '''# File is user.ini
...     [section1]
...     option1 = False
...     # end of file'''.splitlines()
>>> c1 = ConfigObj(b)
>>> c2 = ConfigObj(a)
>>> c2.merge(c1)
>>> c2
ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}})
pop(key, default=<object object>)

‘D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised’

popitem()

Pops the first (key,val)

printout()

Print all keywords of this instance to stdout.

This method is meant for debugging purposes.

reload()

Reload a ConfigObj from file.

This method raises a ReloadError if the ConfigObj doesn’t have a filename attribute pointing to a file.

rename(oldkey, newkey)

Change a keyname to another, without changing position in sequence.

Implemented so that transformations can be made on keys, as well as on values. (used by encode and decode)

Also renames comments.

reset()

Clear ConfigObj instance and restore to ‘freshly created’ state.

restore_default(key)

Restore (and return) default value for the specified key.

This method will only work for a ConfigObj that was created with a configspec and has been validated.

If there is no default value for this key, KeyError is raised.

restore_defaults()

Recursively restore default values to all members that have them.

This method will only work for a ConfigObj that was created with a configspec and has been validated.

It doesn’t delete or modify entries without default values.

setdefault(key, default=None)

A version of setdefault that sets sequence if appropriate.

update(indict)

A version of update that uses our __setitem__.

validate(validator, preserve_errors=False, copy=False, section=None)

Test the ConfigObj against a configspec.

It uses the validator object from validate.py.

To run validate on the current ConfigObj, call:

test = config.validate(validator)

(Normally having previously passed in the configspec when the ConfigObj was created - you can dynamically assign a dictionary of checks to the configspec attribute of a section though).

It returns True if everything passes, or a dictionary of pass/fails (True/False). If every member of a subsection passes, it will just have the value True. (It also returns False if all members fail).

In addition, it converts the values from strings to their native types if their checks pass (and stringify is set).

If preserve_errors is True (False is default) then instead of a marking a fail with a False, it will preserve the actual exception object. This can contain info about the reason for failure. For example the VdtValueTooSmallError indicates that the value supplied was too small. If a value (or section) is missing it will still be marked as False.

You must have the validate module to use preserve_errors=True.

You can then use the flatten_errors function to turn your nested results dictionary into a flattened list of failures - useful for displaying meaningful error messages.

validateValues(*args, **kwargs)

Validate the keywords against the spec. Unlike the parent implementation, raise a ValueError if any unknown keywords are present.

values() list of D’s values
walk(function, raise_errors=True, call_on_sections=False, **keywargs)

Walk every member and call a function on the keyword and value.

Return a dictionary of the return values

If the function raises an exception, raise the errror unless raise_errors=False, in which case set the return value to False.

Any unrecognised keyword arguments you pass to walk, will be pased on to the function you pass in.

Note: if call_on_sections is True then - on encountering a subsection, first the function is called for the whole subsection, and then recurses into it’s members. This means your function must be able to handle strings, dictionaries and lists. This allows you to change the key of subsections as well as for ordinary members. The return value when called on the whole subsection has to be discarded.

See the encode and decode methods for examples, including functions.

caution

You can use walk to transform the names of members of a section but you mustn’t add or delete members.

>>> config = '''[XXXXsection]
... XXXXkey = XXXXvalue'''.splitlines()
>>> cfg = ConfigObj(config)
>>> cfg
ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}})
>>> def transform(section, key):
...     val = section[key]
...     newkey = key.replace('XXXX', 'CLIENT1')
...     section.rename(key, newkey)
...     if isinstance(val, (tuple, list, dict)):
...         pass
...     else:
...         val = val.replace('XXXX', 'CLIENT1')
...         section[newkey] = val
>>> cfg.walk(transform, call_on_sections=True)
{'CLIENT1section': {'CLIENT1key': None}}
>>> cfg
ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}})
write(outfile=None, section=None)

Write the current ConfigObj as a file

tekNico: FIXME: use StringIO instead of real files

>>> filename = a.filename
>>> a.filename = 'test.ini'
>>> a.write()
>>> a.filename = filename
>>> a == ConfigObj('test.ini', raise_errors=True)
1
>>> import os
>>> os.remove('test.ini')
writeInputFile(filename, ignore_none=False, yesno=False, smartsort=False)

Write the configuration to a file in the InputConfig format.

Parameters
  • filename (a file path or an open file handle) – The file to write the configuration to.

  • ignore_none (bool) – If True, keywords with a value of None will not be written to the input file.

  • yesno (bool) – If True, boolean keywords will be written as “yes” and “no”, if False, as “True” and “False”.

  • smartsort (bool) – If True, keywords that are identical except for the numbers at the end will be sorted such that “2” will go before “10”.

writeJSON(filename=None)

Write the keywords as a JSON representation. Unlike writeSimplified, this includes the values for all the keywords, not only the non-default ones.

writeSimplified(filename=None, yesno=False)

Writes a simplified input file to “<jobname>.inp”. This input file needs to be run via $SCHRODINGER/glide.

schrodinger.application.glide.glide.read_constraints(gridfile)

Reads the receptor constraints from the specified grid file.

The constraints are actually read from the .cons file. The resulting constraint “type” refers to the atom type in the RECEPTOR, where applicable. Specifically, H-bond and metal-binding constraints.

The matching ligand atom for an H-bond donor receptor constraint should be an H-bond acceptor (by default). Likewire the matching ligand ato for and H-bond acceptor receptor constraint should be a donor (polar H atom).

Other constraint types don’t refer to any specific atom type (Positional, NOE), or require the same atom type in the ligand as in the receptor (Hydrophobic) so the constraint type is valid for both molecules (ligand and receptor).

To get the constraint label, simply do str(Constraint).

Parameters

gridfile – The gridfile name; should be either a .grd or .zip file.

Return type

A list of Constraint objects.

schrodinger.application.glide.glide.read_yaml()

Read mmim_keywords.json and return a list of objects. The read_yaml() name was retained for compatibility.

schrodinger.application.glide.glide.read_keywords_file()

Read the mmim_keywords.json file from the mmshare data directory and return a list of objects.

schrodinger.application.glide.glide.read_keywords_file_as_dict()

Read the mmim_keywords.json file from the mmshare data directory and return a dict of dicts, where the key is the keyword name and the value is the spec for the keyword (see get_keyword for more details).

schrodinger.application.glide.glide.get_keyword(keyword)

Return the specification of a Glide keyword as a dictionary, with keys such as “keyword”, “type”, “default”, “allowed”, “min”, “max”, and “comment”. For the full list and description for each field, see the comments in mmim_keywords.yaml.

schrodinger.application.glide.glide.get_keywords_dicts(jobtypes, include_undocumented=False)

Return the raw mmim_keywords.yaml data filtered to include only the keywords for the requested job types.

schrodinger.application.glide.glide.keyword_spec(jobtypes, include_undocumented=False)

Return a string with the specification of the mmim keywords that are valid for the jobtypes given. Jobtypes should be an iterable with items such as ‘docking’, ‘multi_docking’, or ‘gridgen’. Keywords for jobtype ‘all’ are always included.

By default, undocumented keywords are not included in the return value, but that behavior can be overridden by setting ‘include_undocumented’ to True.

schrodinger.application.glide.glide.validation_specs(jobtype)

Return a list of validation specs for a given jobtype (e.g., ‘docking’ or ‘gridgen’) or list of jobtypes. This includes not only the keywords returned by keyword_spec(jobtype), but also some extra keywords that are supported by glide.py but not by mmim.

schrodinger.application.glide.glide.get_keywords_set(jobtypes)

Return the set of all keywords valid for the given job types.

schrodinger.application.glide.glide.is_gridgen_keyword(keyword)

Return True is a keyword is valid for gridgen jobs.

schrodinger.application.glide.glide.is_docking_keyword(keyword)

Return True is a keyword is valid for docking jobs.

schrodinger.application.glide.glide.calc_ligand_size(st, ligand_atom_indices)

Given a list of (x, y, z) coordinates for all atoms in a ligand, calculate the ligand size. This value should be added to the innerbox to get the default outerbox.

Parameters
  • st (structure.Structure) – ligand structure

  • ligand_atom_indices (ligand atoms, by atom index) – list[int]

Return type

float

Returns

The size of the ligand.

schrodinger.application.glide.glide.get_default_box_size(struct, ligand_asl='all')

Gets the default box size for a grid. This returns the outer and inner box lengths.

Parameters
  • struct (structure.StructureReader) – The structure containing the reference ligand

  • ligand_asl (str) – The ASL for the ligand. Default: “all”

Return type

tuple of lists, e.g. ([10, 10, 10], [-5.9863, -1.887 , -0.2703])

schrodinger.application.glide.glide.is_gridgen_job(keywords)

Return True if the keywords suggest that this is a gridgen job.

Return type

bool

schrodinger.application.glide.glide.get_glide_job(input_file)

Return a Gridgen or Dock object given an SIF input filename or keyword dictionary. If it is a filename, use it to set JOBNAME (e.g. for “dir/myjob.in”, set it to “myjob”).

schrodinger.application.glide.glide.is_false(val)
schrodinger.application.glide.glide.is_equivalent_to_mininplace(val)

Checks if val is equivalent to mininplace

schrodinger.application.glide.glide.get_default_docking_keyword_value(keyword)

Return the default value for a docking keyword.