schrodinger.application.inputconfig module¶
A modified version of the configobj module.
This module can be used to read and write simplified input file (SIF) formats, such as those used by VSW, Prime, Glide, MacroModel, etc.
The SIF format is related to the Windows INI (.ini) format that is read and writen by configobj, but with following exceptions:
Spaces are used instead of equals signs to separate keywords from values.
Keywords should be written in upper case. (The reading of keywords is case-sensitive).
Example input file:
KEYWORD1 value
KEYWORD2 "value with $special$ characters"
KEYWORD3 item1, item2, item3
KEYWORD4 True
KEYWORD5 10.2
KEYWORD6 1.1, 2.2, 3.3, 4.4
[ SECTION1 ]
SUBKEYWORD1 True
SUBKEYWORD2 12345
SUBKEYWORD3 "some string"
#END
For more information on ConfigObj, see: http://www.voidspace.org.uk/python/configobj.html
Copyright Schrodinger, LLC. All rights reserved.
- schrodinger.application.inputconfig.custom_is_list(value, min=None, max=None)¶
This list validator turns single items without commas into 1-element lists. The default list validator requires a trailing comma for these.
That is, with this function as the list validator and a list spec, an input line of “indices = 1” will create a value of [1] for the key ‘indices’.
- schrodinger.application.inputconfig.custom_is_string_list(value, min=None, max=None)¶
Custom is_string_list() method which overrides the one in validate.py. This method does not raise an exception if a string is passed, and instead tries to break it into a list of strings.
- class schrodinger.application.inputconfig.InputConfig(infile=None, specs=None)¶
Bases:
configobj.ConfigObj
Parse keyword-value input files and make the settings available in a dictionary-like fashion.
Typical usage:
list_of_specs = ["NUM_RINGS = integer(min=1, max=100, default=1)"] config = InputConfig(filename, list_of_specs) if config['NUM_RINGS'] > 4: do_something()
- __init__(infile=None, specs=None)¶
- Parameters
infile (string or dict) – The name of the input file or a dictionary of config keywords and values.
specs (list of strings) – A list of strings, each in the format
<keywordname> = <validator>(<validatoroptions>)
. An example string isNUM_RINGS = integer(min=1, max=100, default=1)
. For available validators, see: http://www.voidspace.org.uk/python/validate.html.
- getSpecsString()¶
Return a string of specifications. One keywords per line. Raises ValueError if this class has no specifications.
- printout()¶
Print all keywords of this instance to stdout.
This method is meant for debugging purposes.
- 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”.
- 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.
- schrodinger.application.inputconfig.determine_jobtype(inpath)¶
Parse the specified file and determines its job type.
This is needed in order to avoid parsing of an input file if its job type is invalid.
Return the job type as a string, or the empty string if no JOBTYPE keyword is found.