schrodinger.application.matsci.msutils module¶
Utility functions and classes for MatSci workflows.
Copyright Schrodinger, LLC. All rights reserved.
-
schrodinger.application.matsci.msutils.
remove_properties
(struct, props=None, matches=None, atom_props=None, atom_matches=None)¶ Remove all the matching structure and atom properties. No error is thrown if the given properties do not actually exist on the structure.
Parameters: - props (list) – A list of structure properties to delete
- matches (list) – Remove all structure properties whose name contains any of these strings
- atom_props (list) – A list of atom properties to delete
- atom_matches (list) – Remove all atom properties whose name contains any of these strings
-
schrodinger.application.matsci.msutils.
remove_atom_property
(struct, prop)¶ Delete atom property from all atoms in a structure (structure will be modified).
Parameters: - struct (
structure.Structure
) – Structure object to be modified - prop (str) – Atom property to be removed
- struct (
-
schrodinger.application.matsci.msutils.
has_atom_property
(struct, prop)¶ Check if structure has any atom with the property set.
Parameters: - structure.Structure – Input structure
- str – Property name
Raises: Return bool: True of property is present, False otherwise
-
schrodinger.application.matsci.msutils.
roundup
(inp)¶ Round away from zero (to +/-infinity).
Parameters: inp (float or numpy.array) – value to be rounded Return type: float or numpy.array Returns: Rounded value
-
schrodinger.application.matsci.msutils.
getstr
(ret)¶ Convert binary string (or other data) to str.
Parameters: ret (binary_type or any other type convertable to str) – Value to be converted to str Return type: str Returns: Value converted to str
-
schrodinger.application.matsci.msutils.
sig_fig_round
(value, significant_figure=5)¶ Parameters: - value (float) – change the significant figures of this value
- significant_figure (int) – significant figure of the displayed value
Return type: str
Returns: str representation of a number with proper significant figures
-
schrodinger.application.matsci.msutils.
get_significant_figures
(number)¶ Get significant digits of a number
Parameters: number (float or int or str) – number to find significant digits Return type: int Returns: number of significant digits
-
schrodinger.application.matsci.msutils.
set_significant_figures
(number, sig_fig)¶ Set significant digits of a number
Parameters: - number (float or int) – number to set significant digits
- sig_fig (int) – number of significant digits
Return type: float
Returns: number with desired significant digits
-
schrodinger.application.matsci.msutils.
get_project_group_hierarchy
(st=None, row=None)¶ Return the project group hierarchy for the given structure or row.
Parameters: - st (
schrodinger.structure.Structure
) – the structure - row (
schrodinger.project.ProjectRow
) – the project row
Raises: ValueError – if there is an issue
Return type: list
Returns: the hierarchy (outermost to innermost)
- st (
-
schrodinger.application.matsci.msutils.
set_project_group_hierarchy
(st, hierarchy, collapsed=False)¶ Set the project group hierarchy for the given structure.
Parameters: - st (
schrodinger.structure.Structure
) – the structure - hierarchy (list) – the hierarchy (outermost to innermost)
- collapsed (bool) – Whether the group should initially be collapsed
- st (
-
schrodinger.application.matsci.msutils.
get_matsci_user_data_dir
()¶ Get the absolute path to the user’s local MatSci data directory for storing custom templates, protocols, etc. Directory is created if it doesn’t exist.
Return type: str Returns: The absolute path the Materials Science data parent directory
-
schrodinger.application.matsci.msutils.
structure_reader
(filename, log=None)¶ Read structures from a file until the end or the first structure with an error.
Parameters: - filename (str) – filename
- log (function) – Log function, if None, nothing is called
Yield schrodinger.structure.Structure: Next structure in the file
-
schrodinger.application.matsci.msutils.
is_dummy_atom
(atom)¶ Return True if the given atom is a dummy atom.
Parameters: atom (schrodinger.structure._StructureAtom) – the atom Return type: bool Returns: return True if the given atom is a dummy atom
-
schrodinger.application.matsci.msutils.
add_or_update_bond_order
(ct, atom1, atom2, bond_order)¶ Create a new bond, or update the existing bond order of this bond.
Return type: schrodinger.structure._Bond
-
schrodinger.application.matsci.msutils.
add_or_update_bond_type
(ct, atom1, atom2, bond_type)¶ Create a new bond, or update the existing bond type of this bond.
Return type: schrodinger.structure._Bond
-
schrodinger.application.matsci.msutils.
polyfit
(xdata, ydata, degree)¶ Fit a polynomial of rang degree to data.
Parameters: - xdata (numpy.array) – X data
- ydata (numpy.array) – Y data
- degree (int) – Degree of the fitting polynomial
Return type: numpy.array, float
Returns: Fitting coefficients, coefficient of determination (R^2)
-
schrodinger.application.matsci.msutils.
trim_str
(text, max_len, suffix='...')¶ Trim the string to approximately max_len. Add a suffix if the string is longer than max_len.
Parameters: - text – String to trim
- max_len (int) – Max length of the string
- suffix (str) – Suffix to add if the string is to be trimmed
Return str: Trimmed string
-
schrodinger.application.matsci.msutils.
mmlewis_apply
()¶ Context manager that initializes mm and returns mm.mmlews_apply method.
Yield: mm.mmlewis_apply method. Example usage:
- with msutils.mmlewis_apply() as lewis_apply:
- assert lewis_apply(struct) is None
-
schrodinger.application.matsci.msutils.
get_disorder_groups
(struct)¶ Get atoms that have s_cif_disorder_group set and occupancies are not 0 or 1.
Parameters: structure.Structure – Input structure Return type: dict or None Returns: Dict with keys disorder group labels, values list of atom indices or None if nothing is present in the structure
-
schrodinger.application.matsci.msutils.
get_atom_ffio_velocity
(atom)¶ Get FFIO atom velocities.
Parameters: atom (structure._StructureAtom) – Input atom Return numpy.array: Array of velocities
-
schrodinger.application.matsci.msutils.
set_atom_ffio_velocity
(atom, velocity)¶ Set FFIO atom velocities.
Parameters: - atom (structure._StructureAtom) – Atom to modify
- velocity (list) – List of velocities (x, y, z components)
-
schrodinger.application.matsci.msutils.
get_unique_name
(new_name, existing_names)¶ Add a suffix to new_name to make a unique name if it already exists in existing_names.
Parameters: - new_name (str) – The new name
- existing_names (list) – Existing names
Return type: str
Returns: The unique version of new_name
-
schrodinger.application.matsci.msutils.
setting_to_bool
(string, empty_is_false=True)¶ Convert a yes/no/true/false/1/0/on/off type string to a Python boolean
Parameters: - string (str) – The string to convert
- empty_is_false – If the string is empty or None, return False
Return type: bool
Returns: True if the string is a “true”-y word (TRUE, true, t, yes, on, 1, etc), False if it is a “false”-y word (FALSE, false, f, no, off, 0).
Raises: - ValueError – If the string cannot be interpreted in a True/False manner
- AttributeError – If something other than a string is passed in
-
schrodinger.application.matsci.msutils.
get_ordered_polymer_backbone
(struct, backbone_path, remove_side_chain)¶ Backbone of a polymer chain should follow H–TH–TH–T format, where backbone starts with head and ends with tail.
Parameters: - struct (schrodinger.structure.Structure) – The structure to find backbone atoms in.
- backbone_path (list) – list of atom indexes in the backbone
- remove_side_chain (bool) – If true it will remove the side chain atoms from the backbone in the start and end.
Return list: list of atom indexes in the backbone such that first atom is always a head.
-
schrodinger.application.matsci.msutils.
get_ordered_backbone_atoms
(struct)¶ Return dictionary of backbone atoms for each molecule in the structure.
Parameters: struct (schrodinger.structure.Structure) – The structure to find backbone atoms in. Return dict(list): the key of the dictionary is molecule number and the value is the list of backbone atoms
-
schrodinger.application.matsci.msutils.
flatten
(alist, afunc=None)¶ Flatten the given list into a set.
Parameters: - alist (list) – elements contain iterable data
- afunc (function or None) – function used to extract iterable data from the given list elements or None if there isn’t one
Return type: set
Returns: a flattened set of data from the given list