Package schrodinger :: Package infra :: Module propedit
[hide private]
[frames] | no frames]

Module propedit

Support functions for Structure property manipulation functions in the propeditor script.

Structures can be created by reading files in any supported format.

Manipulations which can be performed on a Structures properties are:

Copyright Schrodinger, LLC. All rights reserved

Functions [hide private]
 
fxnname()
Return a function's name
 
checkCompatibleTypes(prop1, prop2)
Check that the prop1 can be converted into a prop of type prop2
 
get_op_positions(formula, allowed_operators=['**', '=', '+', '-', '*', '/', '(', ')'])
Get a list of tuples of start and end positions for all operators.
 
checkCT(ct, ranges)
Checks individual structure (ct) for compliance with user input range parameters.
 
merge_op_positions(op_positions)
Merge individual operator positions into a list of all positions of the formula string and whether they contain an operator The result is a list of Boolean values for each character in the formula string indicating if that character is a known operator.
 
generate_groups(formula)
Build 'groups' of the formula pieces, marking each as an operator or not
 
check_formula(formula, existing_properties=[])
Does some basic checking of the formula
 
generate_eval_string(groups, group_types, ct_str='ct')
Generate a string to use in eval for calculation from the groups
 
generate_eval_string_all(formula_part, ct_str='ct')
Generate a string to use in eval for calculation from the formula
 
calcProperty(ct, formula, tocheck_formula=True)
Calculate and set a new property based on calculation from a function of existing properties.
 
listProps(prop_dict)
Print the values for a set of properties.
 
listElements(structure)
Sorts the elements in a list and displays them with a count as the first line
 
sliceProp(ct, propn, newn, startval, endval)
Takes a property, slices its value according to input endpoints and creates a new property with the sliced portion as the value.
 
merge(ct, prop1, prop2, delim, newname)
Merges the value of two properties according a specified delimiter and creates a new property with the merged value and the name 'newname'.
 
addProperty(ct, prop, val, add, num=-1)
Adds a property to the input structure with the given value.
 
copyProperty(ct, prop1, prop2)
Copies the value of one property to another property.
 
renameProperty(ct, prop1, prop2)
Renames a property.
 
delete(ct, prop)
Deletes a property from a structure
 
clear(ct, prop)
Clears the value of a property For integer and float property types sets property value to zero.
 
split(ct, propn, prop1, prop2, delim)
Splits the value of a property according to a given delimiter.
 
conv_bool(value, allow_onezero=True)
Convert a boolean string to True/False.
 
get_type(value, onezero_boolean=True)
Get the type of a string value
 
readData(filename, ct_key_prop, csv_key_prop, tab_delim=False, data={}, prop_group='user', onezero_boolean=True, use_first_value=False, missing_key='MISSINGENTRY')
Read the data of a .csv file into a dict using the csv package.
 
exportFile(ct, fileobj, num, props=[], tab_delim=False)
Exports a .mae file into a .csv file
 
printvals(props, input_fn, rules)
Given a list of properties and an input file prints out the values of every property for every ct in the input file If a set of rules has been entered, first checks if the CT abides by the rules and only prints out property values if it does.
Variables [hide private]
  _version = '$Revision: 1.9 $'
  ranges = []
  compatible_types = {'b': ['b', 'i', 'r', 's'], 'i': ['i', 'r',...
  stepdown_conv = {'b': [''], 'i': ['', 'b'], 'r': ['', 'b', 'i'...
  missing_values = {'b': False, 'i': 0, 'r': 0.0, 's': ''}
  number_regexs = ['^[+-.]$', '[+-]?[0-9]+[.]?[0-9]*[eE][+-]?[0-...
  number_REs = [re.compile(r'^[\+-\.]$'), re.compile(r'[\+-]?[0-...
  prop_RE = re.compile(r'[ribs]_.*?_')
  numeric_prop_RE = re.compile(r'[ri]_.*?_')
  space_RE = re.compile(r'\s')
  allowed_operators = ['**', '=', '+', '-', '*', '/', '(', ')']
  op_REs = [re.compile(r'\*\*'), re.compile(r'='), re.compile(r'...
  allowed_functions = [<built-in function acos>, <built-in funct...
  allowed_function_names = ['acos', 'asin', 'atan', 'cos', 'cosh...
  allowed_function_modules = {'acos': 'math', 'asin': 'math', 'a...
  conv_functions = {'b': conv_bool, 'i': int, 'r': float, 's': str}
  conv_keys = ['b', 'i', 'r', 's']
  __package__ = 'schrodinger.infra'
  re_str = '[)]'
  y = ')'
Function Details [hide private]

get_op_positions(formula, allowed_operators=['**', '=', '+', '-', '*', '/', '(', ')'])

 

Get a list of tuples of start and end positions for all operators. These tuples may be overlapping (e.g., * also matches **, so ** is included twice) and will not be sorted. Generally, these positions will be processed by merge_op_positions.

checkCT(ct, ranges)

 

Checks individual structure (ct) for compliance with user input range parameters. 'ranges' contains a list of lists - ranges[i][0] is the property name ranges[i][1] is the minimum value ranges[i][2] is the maximum value Boolean properties are checked against ranges[i][1] which can be True or False

Returns True if 'ct' complies with all range parameters, False otherwise

False is returned if the property name is not known or if there is some other type of exception when retrieving it.

check_formula(formula, existing_properties=[])

 

Does some basic checking of the formula

The checks include: 1) Must have 1 and only 1 = 2) To the left of the = must be a valid real or int property 3) Must have only allowed operators, allowed functions, property names, or numbers (ints or float) 4) (optional) Must have only existing properties

calcProperty(ct, formula, tocheck_formula=True)

 

Calculate and set a new property based on calculation from a function of existing properties. The formula must be of the form: new_property = <old_property|operator|function|constant>

listProps(prop_dict)

 

Print the values for a set of properties. The properties are sorted alphabetically.

sliceProp(ct, propn, newn, startval, endval)

 

Takes a property, slices its value according to input endpoints and creates a new property with the sliced portion as the value. Boolean properties cannot be sliced.

addProperty(ct, prop, val, add, num=-1)

 

Adds a property to the input structure with the given value. If a property of that name already exists then it will overwritten.

copyProperty(ct, prop1, prop2)

 

Copies the value of one property to another property. If the source property does not exist then the destination (prop2) is set to a default value - 0, '' or False depending on the type.

renameProperty(ct, prop1, prop2)

 

Renames a property. Algorithm: Create a new property with the new name, copy values of the old property to the new property and delete the old property. Uses copy and delete methods.

clear(ct, prop)

 

Clears the value of a property For integer and float property types sets property value to zero. For string property types sets property value to "" For boolean property type sets property value to False

split(ct, propn, prop1, prop2, delim)

 

Splits the value of a property according to a given delimiter. Creates two new properties. Property values of these new properties are the pieces of the old property that remain after the split.

conv_bool(value, allow_onezero=True)

 

Convert a boolean string to True/False.

The following are considered True: True, T (case insensitive), 1 (if allow_onezero is True) The following are considered False: False, F (case insensitive), 0 (if allow_onezero is True) If the value doesn't match either of these, a ValueError is raised.

get_type(value, onezero_boolean=True)

 

Get the type of a string value

The types are assigned based on drop-down, conversion 1) boolean (b), else 2) int (i), else 3) float (r), else 4) string (s)

readData(filename, ct_key_prop, csv_key_prop, tab_delim=False, data={}, prop_group='user', onezero_boolean=True, use_first_value=False, missing_key='MISSINGENTRY')

 

Read the data of a .csv file into a dict using the csv package.

This assumes the first line is a list of properties.

Returns a tuple of (data, ok_status). (If no problems were encountered, ok_status is True, otherwise it is False.)

This also assigns property types as follows:

  1. If the property name matches [ribs]_, the type is determined from the prefix.
  2. The property values are then checked to see if it is convertible to
    1. boolean (with handling for True|T|1 or False|F|0), else
    2. int, else
    3. float (assigned real), else
    4. string

The types are based on the 'least stringent' of the data, e.g., data with values of 1.0,3.4,1 ==> float, with values of 1.0,4,3a ==> string. If all values are 1|0 and <onezero_boolean> is True, the property is assumed to be a boolean

This also builds a dictionary of valid values for missing instances when doing the import. The values are:

  • boolean: False
  • int : 0
  • real : 0.0
  • string : ''

printvals(props, input_fn, rules)

 

Given a list of properties and an input file prints out the values of every property for every ct in the input file If a set of rules has been entered, first checks if the CT abides by the rules and only prints out property values if it does. See checkCT for a description of how the 'rules' are specified.


Variables Details [hide private]

compatible_types

Value:
{'b': ['b', 'i', 'r', 's'],
 'i': ['i', 'r', 's'],
 'r': ['r', 's'],
 's': ['s']}

stepdown_conv

Value:
{'b': [''],
 'i': ['', 'b'],
 'r': ['', 'b', 'i'],
 's': ['', 'b', 'i', 'r']}

number_regexs

Value:
['^[+-.]$',
 '[+-]?[0-9]+[.]?[0-9]*[eE][+-]?[0-9][0-9]*',
 '[+-]?[0-9]*[.]?[0-9]+[eE][+-]?[0-9][0-9]*',
 '[+-]?[0-9]+[.][0-9]*',
 '[+-]?[0-9]*[.][0-9]+',
 '[+-]?[0-9]+']

number_REs

Value:
[re.compile(r'^[\+-\.]$'),
 re.compile(r'[\+-]?[0-9]+\.?[0-9]*[eE][\+-]?[0-9][0-9]*'),
 re.compile(r'[\+-]?[0-9]*\.?[0-9]+[eE][\+-]?[0-9][0-9]*'),
 re.compile(r'[\+-]?[0-9]+\.[0-9]*'),
 re.compile(r'[\+-]?[0-9]*\.[0-9]+'),
 re.compile(r'[\+-]?[0-9]+')]

op_REs

Value:
[re.compile(r'\*\*'),
 re.compile(r'='),
 re.compile(r'\+'),
 re.compile(r'-'),
 re.compile(r'\*'),
 re.compile(r'/'),
 re.compile(r'\('),
 re.compile(r'\)')]

allowed_functions

Value:
[<built-in function acos>,
 <built-in function asin>,
 <built-in function atan>,
 <built-in function cos>,
 <built-in function cosh>,
 <built-in function degrees>,
 <built-in function exp>,
 <built-in function fabs>,
...

allowed_function_names

Value:
['acos',
 'asin',
 'atan',
 'cos',
 'cosh',
 'degrees',
 'exp',
 'fabs',
...

allowed_function_modules

Value:
{'acos': 'math',
 'asin': 'math',
 'atan': 'math',
 'cos': 'math',
 'cosh': 'math',
 'degrees': 'math',
 'exp': 'math',
 'fabs': 'math',
...