schrodinger.application.matsci.codeutils module

Module for utilities related to code maintenance

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.application.matsci.codeutils.ModuleInfo(parents, name)

Bases: tuple

name

Alias for field number 1

parents

Alias for field number 0

schrodinger.application.matsci.codeutils.check_moved_variables(var_name, moved_variables, module_name)

Check if the target variable has been moved. If yes, post a warning when it was moved this or last release, and raise an error if it has been longer than that. Raises AttributeError if the variable was not moved.

Parameters
  • var_name (str) – Name of the target variable

  • moved_variables (tuple) – Tuple of tuples. Each inner tuple has a format of (module, moved_release, variables), where module is the new module name, moved_release is the release in which the variable was moved, and variables are the set of variables that were moved

  • module_name (str) – Name of the calling module, for attribute error msg

Raises

AttributeError – If var_name is not a moved variable

Return type

Any

Returns

The moved variable

schrodinger.application.matsci.codeutils.is_python_file(path)

Return whether the passed path is a python file

Parameters

path (str) – The file path

Return type

bool

Returns

Whether the path is a python file

schrodinger.application.matsci.codeutils.get_matsci_module_paths()

Return a dict of file paths and dot paths of all matsci modules, sorted

Return dict

A dict mapping file paths to dot paths

class schrodinger.application.matsci.codeutils.MissingModule(msg=None)

Bases: object

Dummy class to return instead of missing modules. Will raise if any attribute is accessed.

__init__(msg=None)
Parameters

msg (str) – the exception message

schrodinger.application.matsci.codeutils.get_safe_package(name)

Get a desmond or jaguar package without raising if the package doesn’t exist

Parameters

name (str) – “namespace.package” where namespace is either desmond or jaguar

Raises
  • ValueError – If the namespace is not included or correct

  • ImportError – If the package name is incorrect

Return type

module or MissingModule

Returns

The module or a MissingModule object

schrodinger.application.matsci.codeutils.get_imports(script_path, parent_required='matsci')

Gets all the imported module/methods in the passed script

Parameters
  • script_path (str) – The script path

  • parent_required (str) – Only include the methods and modules from the passed parent.

Returns

iterator of module info of imported module/methods

Return type

iter

schrodinger.application.matsci.codeutils.get_matsci_module_graph()

Get the directed graph for matsci module imports

Returns

Directed graph where each node is a matsci module and the edge represents importing of the module.

Return type

networkx.DiGraph

schrodinger.application.matsci.codeutils.is_python_pre311()

Check if the current Python version is earlier than 3.11

Return type

bool

Returns

True if using Python < 3.11, False if not

schrodinger.application.matsci.codeutils.is_missing_module(module)

Return True if the given module is a MissingModule.

Parameters

module (module or MissingModule) – the module

Return type

bool

Returns

True if the given module is a MissingModule

schrodinger.application.matsci.codeutils.get_enc_module()

Return the enc.py module.

Return type

module or MissingModule

Returns

the module or MissingModule