schrodinger.application.prime.wrapper module¶
Classes to assist in preparing prime input files
- class schrodinger.application.prime.wrapper.PrimeConfig(kw=None)¶
Bases:
schrodinger.application.inputconfig.InputConfig
Class for reading and writing simplified Prime homology modeling input files.
- specs = ["JOB_TYPE = string(default='MODEL')", "DIR_NAME = string(default='.')", 'QUERY_OFFSET = integer(default=0)', 'TAILS = integer(default=0)', "SIDE_OPT = string(default='false')", "MINIMIZE = string(default='true')", "BUILD_INSERTIONS = string(default='true')", 'MAX_INSERTION_SIZE = integer(default=20)', "BUILD_TRANSITIONS = string(default='true')", "BUILD_DELETIONS = string(default='true')", "KEEP_ROTAMERS = string(default='true')", "KNOWLEDGE_BASED = string(default='true')", 'NUM_OUTPUT_STRUCT = integer(default=1)', "TEMPLATE_RESIDUE_NUMBERS = string(default='false')"]¶
- __init__(kw=None)¶
Accepts one argument which is either a path or a keyword dictionary.
- setAlignment(alignment, ligands=('all',), include_water=False, template_number=1)¶
- Parameters
alignment (
BasePrimeAlignment
) – Alignment.ligands (tuple of str) – Names of ligands to be included in the model.
include_water (bool) – Whether to include water molecules in the built model.
template_number (int) – Template number
- writeConfig(filename)¶
Writes a simplified input file to filename.
This input file needs to be run via
$SCHRODINGER/prime
.- Parameters
filename (str) – Name of output file.
- __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
, or1
it returnsTrue
.If the string is one of
False
,Off
,No
, or0
it returnsFalse
.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
, aValueError
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
, aValueError
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 theirdict
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.
- 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 valueTrue
. (It also returnsFalse
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
isTrue
(False
is default) then instead of a marking a fail with aFalse
, it will preserve the actual exception object. This can contain info about the reason for failure. For example theVdtValueTooSmallError
indicates that the value supplied was too small. If a value (or section) is missing it will still be marked asFalse
.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(preserve_errors=True, copy=True)¶
Validate the values read in from the InputConfig file.
Provide values for keywords with validators that have default values.
If a validator for a keyword is specified without a default and the keyword is missing from the input file, a RuntimeError will be raised.
- Parameters
preserve_errors (bool) –
- If set to False, this method returns True if
all tests passed, and False if there is a failure. If set to True, then instead of getting False for failed checkes, the actual detailed errors are printed for any validation errors encountered.
Even if preserve_errors is True, missing keys or sections will still be represented by a False in the results dictionary.
copy (bool) – If False, default values (as specified in the ‘specs’ strings in the constructor) will not be copied to object’s “defaults” list, which will cause them to not be written out when writeInputFile() method is called. If True, then all keywords with a default will be written out to the file via the writeInputFile() method. NOTE: Default is True, while in ConfigObj default is False.
- 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 toFalse
.Any unrecognised keyword arguments you pass to walk, will be pased on to the function you pass in.
Note: if
call_on_sections
isTrue
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.prime.wrapper.ConsensusConfig(kw=None)¶
Bases:
schrodinger.application.inputconfig.InputConfig
Class for reading and writing simplified Prime consensus modeling input files.
- specs = ["ALIGN_FILE = string()SC_OPT = string(default='yes')"]¶
- __init__(kw=None)¶
Accepts one argument which is either a path or a keyword dictionary.
- setAlignment(alignment)¶
- writeConfig(filename)¶
Writes a simplified input file to filename.
This input file needs to be run via
$SCHRODINGER/consensus_homology
.- Parameters
filename (str) – Name of output file.
- __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
, or1
it returnsTrue
.If the string is one of
False
,Off
,No
, or0
it returnsFalse
.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
, aValueError
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
, aValueError
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 theirdict
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.
- 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 valueTrue
. (It also returnsFalse
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
isTrue
(False
is default) then instead of a marking a fail with aFalse
, it will preserve the actual exception object. This can contain info about the reason for failure. For example theVdtValueTooSmallError
indicates that the value supplied was too small. If a value (or section) is missing it will still be marked asFalse
.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(preserve_errors=True, copy=True)¶
Validate the values read in from the InputConfig file.
Provide values for keywords with validators that have default values.
If a validator for a keyword is specified without a default and the keyword is missing from the input file, a RuntimeError will be raised.
- Parameters
preserve_errors (bool) –
- If set to False, this method returns True if
all tests passed, and False if there is a failure. If set to True, then instead of getting False for failed checkes, the actual detailed errors are printed for any validation errors encountered.
Even if preserve_errors is True, missing keys or sections will still be represented by a False in the results dictionary.
copy (bool) – If False, default values (as specified in the ‘specs’ strings in the constructor) will not be copied to object’s “defaults” list, which will cause them to not be written out when writeInputFile() method is called. If True, then all keywords with a default will be written out to the file via the writeInputFile() method. NOTE: Default is True, while in ConfigObj default is False.
- 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 toFalse
.Any unrecognised keyword arguments you pass to walk, will be pased on to the function you pass in.
Note: if
call_on_sections
isTrue
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.prime.wrapper.PrimeTemplate(pdb_id='')¶
Bases:
schrodinger.application.prime.wrapper._WorkingDirectoryMixin
This class encapsulates Prime template structure. A template includes a single chain.
- WATER_NAMES = {'HOH', 'WAT'}¶
- FIND_LIGANDS_KWARGS = {'allow_ion_only_molecules': True, 'excluded_residue_names': {'HOH', 'WAT'}, 'min_heavy_atom_count': 1}¶
- __init__(pdb_id='')¶
- property file_name¶
- property st¶
- property ligands¶
Returns a list of ligands found in the template structure.
- Return type
list of
schrodinger.structuils.analyze.Ligand
objects- Returns
List of ligands in current template structure.
- property waters¶
- writePDB()¶
Writes template structure to PDB file.
- Return type
bool
- Returns
True on successful write.
- prependWorkingDirectory(path)¶
If it’s set, prepend the working directory to the given path.
- Parameters
path (str) – Path to modify
- Returns
Modified path
- Return type
str
- setWorkingDirectory(wd)¶
Set directory used to write files
- Parameters
wd (str) – Path of the working directory
- class schrodinger.application.prime.wrapper.BasePrimeAlignment(name, query_seq)¶
Bases:
schrodinger.application.prime.wrapper._WorkingDirectoryMixin
Encapsulates pairwise query-template alignment. Allows writing alignment files in Prime format.
- __init__(name, query_seq)¶
- Parameters
name (str) – Alignment name.
query_seq (str) – Text of prealigned query sequence.
- property name¶
- property query_sequence¶
- property template¶
- property template_sequence¶
- setTemplate(template, sequence=None)¶
Adds a pre-aligned template sequence to the alignment.
- Parameters
template (
PrimeTemplate
) – Template.sequence (str) – Template sequence aligned to query (i.e. including gaps).
- setWorkingDirectory(wd)¶
Propagate change in working directory to template
- getAlnFilename()¶
Get the filename of the aln written by
writeInputForPrime
.
- writeInputForPrime()¶
Writes Prime alignment to external file.
- writeInputForConsensus(file_name, append=False)¶
Writes out FASTA alignment for consensus homology modeling. The alignment needs to include chain name and secondary structure definition for each template sequence.
- Parameters
append (bool) – Whether to append to existing file.
file_name (str) – Name of output file.
- getSSA(st, chain_id='')¶
Gets a secondary structure annotation string for structure st chain chain_id.
- Parameters
st (
schrodinger.structure.Structure
) – Input structure.chain_id (str) – Chain ID to extract SSA from.
- prependWorkingDirectory(path)¶
If it’s set, prepend the working directory to the given path.
- Parameters
path (str) – Path to modify
- Returns
Modified path
- Return type
str
- schrodinger.application.prime.wrapper.basename_no_ext(file_name)¶
Returns file basename without extension.
- schrodinger.application.prime.wrapper.convert_gaps_to_dots(sequence)¶
Replaces gap symbols with dots to make a sequence compatible with Prime.
- Parameters
sequence (str) – Input gapped sequence.
- Return type
str
- Returns
Converted sequence.
- schrodinger.application.prime.wrapper.convert_gaps_to_tildes(sequence)¶
Replaces gap symbols with tildes to make a sequence compatible with consensus modeling.
- Parameters
sequence (str) – Input gapped sequence.
- Return type
str
- Returns
Converted sequence.