Source code for schrodinger.infra.mm

"""
Python-level wrappers for the SWIG-wrapped C and C++ functions.

This module exists to make use of pymmlibs a bit easier and provides access
to all functions and constants present in that module.

It adds a layer of automatic error checking to the SWIG wrapped mmlib
functions. Instead of returning function return values to the user, the
values are checked for indication of failure. If a failure occurs, an
MmException is raised. (The underlying return code can be accessed as the
'rc' attribute of an MmException.) If a failure does not occur, the caller
will not see the mmlib function return value at all.

To access the mmlibs functions in their "pure" form (i.e. the basic SWIG
wrapped functions without automatic error checking) use the pymmlibs
module, which can be imported with 'import pymmlibs'.

To call mmlibs functions from python, use input arguments of the
appropriate type. Output arguments will be returned as function return
values. In the event that there are multiple output arguments, a tuple of
these values will be returned. (If you are using functions from the pymmlibs
module, the first value in your return tuple will always be the return
value of the C function.)

Some mmlibs debugging and profiling niceties are provided through this
module. For debugging python calls to mmlibs, you can set
SCHRODINGER_PYTHON_MMLIBS_TRACE to any non-null value to get a debug-level
logger that prints every call to a wrapped mmlibs function. For assistance in
profiling, set SCHRODINGER_PYTHON_CPROFILE to a non-null value. This will set
up an additional wrapper with a unique name for each mmlib function so they
can be attributed in profiles run via the `cProfile` module. Without
SCHRODINGER_PYTHON_CPROFILE, all mmlibs calls will be attributed to the
`_Wrapper.__call__` method.

"""
# Copyright Schrodinger, LLC. All rights reserved.

import os

from schrodinger.infra import mmcheck

try:
    SCHRODINGER = os.environ['SCHRODINGER']
except KeyError:
    raise Exception("SCHRODINGER is not defined.")

# Try to find MMSHARE_EXEC if it's not present.
if 'MMSHARE_EXEC' not in os.environ:
    from schrodinger.job.util import hunt
    os.environ['MMSHARE_EXEC'] = hunt("mmshare")

try:
    import pymmlibs
except ImportError:
    # if PYTHONHOME isn't defined or SCHRODINGER isn't part of it, then
    # $SCHRODINGER/run probably isn't being used. This wrapper
    # script sets up PYTHONHOME, PYTHONPATH, and LD_LIBRARY_PATH as needed
    # to access mm.py, pymmlibs.py, and _pymmlibs.so.
    if SCHRODINGER not in os.environ.get('PYTHONHOME', ""):
        raise ImportError(
            "Please use $SCHRODINGER/run to launch python scripts.")

    # If something else was the source of the problem, just reraise the
    # original ImportErr
    raise


[docs]def set_globals(): # Add an alias for mmffld_minimize_lic for API compatibility with # existing scripts. globals_ = globals() globals_['mmffld_minimize'] = globals_['mmffld_minimize_lic']
Null = mmcheck.Null # # mmlib functions generally return X_OK when the function succeeds and X_ERR # when it does not. There are numerous exceptions to this rule, however. In # some cases the return code returns a value to be used, and X_ERR when it # fails. In other cases, the return value is always meant to be used. # # For functions in which the X_OK, X_ERR paradigm is not followed, the # failure dictionary below records the value for which an exception should # be raised in the error checking wrapper. # # For example, mmct_atom_get_bond_total generally returns the number of # bonds to an atom, but if an error is encountered, it returns MMCT_ERROR. # As another example, the value of the mmct_refcount function should # always be used, so it is given the special value Null, which as an # instance of object will never match a C function return value, and so its # return value will never cause an exception to be raised. # _failure = { 'aacg_vdw_parameters': Null, 'MmaslLigandPref_Instance': Null, 'find_ligand_atoms': Null, 'find_ligand_molecules': Null, 'get_download_center_url': Null, 'get_knime_workflows_url': Null, 'ligprep3_refcount': Null, 'ligprep3_initialize': pymmlibs.LIGPREP3_FAILURE, 'm2io_refcount': Null, 'mmalign_get_aligned_sequence': Null, 'mmalign_get_end_position': Null, 'mmalign_get_evalue': Null, 'mmalign_get_num_aligned_sequences': Null, 'mmalign_get_percent_gaps': Null, 'mmalign_get_percent_identity': Null, 'mmalign_get_percent_positive': Null, 'mmalign_get_query_sequence': Null, 'mmalign_get_score': Null, 'mmalign_get_start_position': Null, 'mmalign_in_use': Null, 'mmasl_refcount': Null, 'mmat_get_anyatom': Null, 'mmat_get_atom_type': Null, 'mmat_get_atomic_num': Null, 'mmat_get_atomic_number_by_element': Null, 'mmat_get_atomic_weight': Null, 'mmat_get_central_geometry': Null, 'mmat_get_color': Null, 'mmat_get_description': Null, 'mmat_get_element': Null, 'mmat_get_element_by_atomic_number': Null, 'mmat_get_eneg': Null, 'mmat_get_eqat13': Null, 'mmat_get_formal_charge': Null, 'mmat_get_generalized_type': Null, 'mmat_get_hadded': Null, 'mmat_get_largest_atype': Null, 'mmat_get_largest_vdw_radius': Null, 'mmat_get_mmod_name': Null, 'mmat_get_natype': Null, 'mmat_get_next': Null, 'mmat_get_nhua': Null, 'mmat_get_pdb_name': Null, 'mmat_get_solv_eqat13': Null, 'mmat_get_uaroot': Null, 'mmat_get_valence': Null, 'mmat_get_vdw_radius': Null, 'mmat_get_wildcard': Null, 'mmat_is_catdel': Null, 'mmat_is_deloc': Null, 'mmat_is_generalized_type': Null, 'mmat_is_valid': Null, 'mmat_is_wildcard': Null, 'mmbs_all': -1, 'mmbs_and': -1, 'mmbs_any': -1, 'mmbs_get_count': -1, 'mmbs_get_next': Null, 'mmbs_get_previous': Null, 'mmbs_get_size': -1, 'mmbs_in_use': Null, 'mmbs_is_off': Null, 'mmbs_is_on': Null, 'mmbs_none': -1, 'mmbs_not': -1, 'mmbs_or': -1, 'mmbs_xor': -1, 'mmcolor_rgb_to_vector': Null, 'mmcolor_vector_set': Null, 'mmcolor_vector_to_index': Null, 'mmcolor_vector_to_rgb': Null, 'mmcolor_vector_to_string': Null, 'mmcolor_vectors_equal': Null, 'mmcommon_display_ffbuilder': Null, 'mmcommon_display_opls2': Null, 'mmcommon_web_access_allowed': Null, 'mmcommon_display_scisol': Null, 'mmcommon_display_watermap': Null, 'mmcommon_get_license_feature_version': Null, 'mmcommon_get_scratch_project_regular_expression': Null, 'mmcrystal_tag_ok': Null, 'mmct_atom_get_atom_entry': Null, 'mmct_atom_get_atom_mol': Null, 'mmct_atom_get_atomic_number': pymmlibs.MMCT_ERROR, 'mmct_atom_get_atomic_weight': pymmlibs.MMCT_ERROR, 'mmct_get_molecular_weight': pymmlibs.MMCT_ERROR, 'mmct_atom_get_bond_angle': Null, 'mmct_atom_get_bond_angle_pbc': Null, 'mmct_atom_get_bond_atom': pymmlibs.MMCT_ERROR, 'mmct_atom_get_bond_order': pymmlibs.MMCT_ERROR, 'mmct_atom_get_bond_total': pymmlibs.MMCT_ERROR, 'mmct_atom_get_chain': pymmlibs.MMCT_ERROR, 'mmct_atom_get_chain_char': Null, 'mmct_atom_get_charge1': Null, 'mmct_atom_get_charge2': Null, 'mmct_atom_get_chargef': Null, 'mmct_atom_get_color': Null, 'mmct_atom_get_dihedral_angle': Null, 'mmct_atom_get_dihedral_angle_pbc': Null, 'mmct_atom_get_distance': Null, 'mmct_atom_get_distance_pbc': Null, 'mmct_atom_get_entry_mol_num': Null, 'mmct_atom_get_isotope': pymmlibs.MMCT_ERROR, 'mmct_atom_get_pdb_tfactor': Null, 'mmct_atom_get_res': Null, 'mmct_atom_get_res_num': pymmlibs.MMCT_ERROR, 'mmct_atom_get_secondary_struct': Null, 'mmct_atom_get_type': pymmlibs.MMCT_ERROR, 'mmct_atom_get_x': Null, 'mmct_atom_get_y': Null, 'mmct_atom_get_z': Null, 'mmct_atom_has_alt_position': Null, 'mmct_atom_is_selected': Null, # Note that mmct_bond_get_order returns MMCT_ERROR when no bond exists, # while mmct_atom_get_bond_order returns MMCT_NONE. For this reason, # don't raise an exception for mmct_bond_get_order, instead return # MMCT_ERROR explicitly. 'mmct_bond_get_order': Null, 'mmct_current_errhandler': Null, 'mmct_ct_compare': pymmlibs.MMCT_ERROR, 'mmct_ct_compare_connect': pymmlibs.MMCT_ERROR, 'mmct_ct_compare_jaguar_geometry': Null, 'mmct_ct_get_all_xyz_copy': Null, 'mmct_ct_get_all_xyz_live': Null, 'mmct_ct_get_atom_total': pymmlibs.MMCT_ERROR, 'mmct_ct_get_entry_total': pymmlibs.MMCT_ERROR, 'mmct_ct_get_mol_total': pymmlibs.MMCT_ERROR, 'mmct_ct_get_property_dependency': Null, 'mmct_ct_get_xmax': Null, 'mmct_ct_get_xmin': Null, 'mmct_ct_get_ymax': Null, 'mmct_ct_get_ymin': Null, 'mmct_ct_get_zmax': Null, 'mmct_ct_get_zmin': Null, 'mmct_ct_in_use': Null, 'mmct_get_ct_total': pymmlibs.MMCT_ERROR, 'mmct_id_map_get': Null, 'mmct_id_map_get_size': Null, 'mmct_id_map_in_use': Null, 'mmct_is_atom_bonded': pymmlibs.MMCT_ERROR, 'mmct_is_enabled': Null, 'mmct_is_standard_biopolymer': Null, 'mmct_is_standard_nucleotide': Null, 'mmct_is_standard_residue': Null, 'mmct_refcount': Null, 'mmct_res_connected': Null, 'mmct_valid_atom': Null, 'mmelement_get_atomic_number_by_symbol': Null, 'mmelement_get_atomic_weight_by_atomic_number': Null, 'mmelement_get_electronegativity_by_atomic_number': Null, 'mmelement_get_atomic_weight_by_symbol': Null, 'mmelement_get_symbol_by_atomic_number': Null, 'mmelement_get_full_valence': Null, 'mmelement_get_max_valence': Null, 'mmelement_get_valence_count': Null, 'mmelement_get_period': Null, 'mmelement_get_default_color': Null, 'mmelement_get_element_name': Null, 'mmerr_return_code': Null, 'mmffld_get_error_handler': Null, 'mmffld_refcount': Null, 'mmffld_minimize_lic': Null, 'mmfile_get_appdata_release_dir_path': Null, 'mmfile_get_config_dir': Null, 'mmfile_get_directory_path': Null, 'mmfile_get_maestro_scripts_path': Null, 'mmfile_get_product_dir_path': Null, 'mmfile_get_product_directory_names': Null, 'mmim_is_dihedral': Null, 'mmim_is_ringbond': Null, 'mmjag_atomic_number': Null, 'mmjag_basis_count': Null, 'mmjag_key_nondef_count': Null, 'mmjag_scan_adjust': Null, 'mmjag_scan_useable': Null, 'mmjag_terminate': Null, 'mmjag_zmat_count': Null, 'mmlewis_get_error_handler': Null, 'mmlewis_refcount': Null, # mmlist_get is tough because you could store 0 in the list, but 0 is # what is returned on error. Since there's no way to tell if the code is # a real zero or an error, don't fail for anything. # Ditto for mmlist_get_size. 'mmlist_get': Null, 'mmlist_get_size': Null, 'mmlist_in_list': Null, 'mmlist_in_range': Null, 'mmmdl_refcount': Null, 'mmmol2_get_total_struct': Null, 'mmmol2_refcount': Null, 'mmneut_get_errhandle': Null, 'mmneut_set_errhandle': Null, 'mmpatty_get_error_handler': Null, 'mmpatty_num_atoms': -1, 'mmpatty_refcount': Null, 'mmpdb_get_three_to_one_letter_residue_map': Null, 'mmpdb_refcount': Null, 'mmpipeline_initialize': Null, 'mmseq_create_sequence_name': Null, 'mmseq_get_accession_number': Null, 'mmseq_get_all_codes': Null, 'mmseq_get_ca_index': Null, 'mmseq_get_chain': Null, 'mmseq_get_chainstr': Null, 'mmseq_get_code': Null, 'mmseq_get_code_ids': Null, 'mmseq_get_code_ids_range': Null, 'mmseq_get_code_range': Null, 'mmseq_get_description': Null, 'mmseq_get_entry_name': Null, 'mmseq_get_id': Null, 'mmseq_get_length': Null, 'mmseq_get_name': Null, 'mmseq_get_subsequence': Null, 'mmseq_get_type': Null, 'mmseq_in_use': Null, 'mmseqio_get_seq_type': Null, 'mmseqio_in_use': Null, 'mmstereo_extra_check_ch_combination': pymmlibs.MMSTEREO_ERR, 'mmsys_get_short_host': Null, 'mmsys_is_localhost': Null, 'mmsys_version_to_string': Null, 'mmtable_is_enabled': Null, 'mmtable_refcount': Null, 'mmtable_table_is_valid': Null, 'mmtable_terminate': Null, 'mmtaut_get_error_handler': Null, 'mmzip_contains_file': Null, 'mmzip_file_name': Null, # coordinate_math.h doesn't use return codes: 'Cartesian_angle': Null, 'Cartesian_dihedral': Null, 'Cartesian_distance': Null, 'Cartesian_square_distance': Null, 'Cartesian_swigregister': Null, 'get_angle_between_two_vectors': Null, 'get_dihedral': Null, 'get_normal_vector_to_three_points': Null, 'get_OPLS_data_subdirectory': Null, 'get_current_OPLS_data_subdirectory': Null, 'get_OPLS_data_filename': Null, 'get_current_OPLS_data_filename': Null, 'get_mmshare_data_directory': Null, 'mmffld_get_loaded_UTTs': Null, 'mmffld_overwrite_vdw_interaction_parameter_IAC': Null, 'mmffld_get_LJ_type_from_symbol': Null, 'mmffld_getEnergyForce': Null, 'mmffld_getAtomicCharges': Null, 'get_structure_UTTs': Null, # TODO: Swig wrap schrodinger::forcefield:: separately from infra.mm # opls_constants.h 'opls_name_to_version': Null, 'opls_version_to_name': Null, 'opls_names': Null, 'int_to_opls_version': Null, 'resolve_archive_path': Null, #preferences.h 'get_preference_custom_opls_path': Null, 'get_preference_opls_version': Null, 'get_preference_use_custom_opls': Null, 'get_preference_most_recent_custom_opls_paths': Null, 'set_preference_custom_opls_path': Null, 'set_preference_opls_version': Null, 'set_preference_use_custom_opls': Null, 'set_preference_most_recent_custom_opls_paths': Null, # opls_directory.h 'validate_opls_directory': Null, 'is_valid_opls_directory': Null, 'get_archive_path': Null, 'get_compatible_archive_path': Null, 'get_ffld_spec': Null, 'ffld_spec_to_string': Null, # opls_license.h 'opls_main_license_exists': Null, 'minimization_license_exists': Null, 'development_license_exists': Null, 'assert_development_license_exists': Null, 'assert_opls_main_license_exists': Null, # opls_archive.h 'OPLSArchive_create': Null, 'OPLSArchive_validate': Null, 'OPLSArchive_isCompatible': Null, 'OPLSArchive_upgrade': Null, # opls_metadata.h 'validate_opls_metadata': Null, 'is_compatible_opls_metadata': Null, 'current_opls_metadata': Null, # opls_datafile.h 'installation_archive_path': Null, # utt_io.h 'read_utts': Null, # torsion_fit_info.h 'get_torsion_fit_info': Null, # drude parameters 'mmffld_getPolarizabilityParameters': Null, 'mmffld_getDrudeForceConstant': Null, } #Please attempt to keep this list alphabetized to make it slightly more sane #and help avoiding adding things twice. mm_return_code_lists = [ ['LIGPREP3_FAILURE', 'LIGPREP3_SUCCESS'], [ 'M2IO_ERR', 'M2IO_OK', 'M2IO_BAD_INDEX', 'M2IO_DATA_ERROR', 'M2IO_EOF', 'M2IO_NOT_WRITING', 'M2IO_NOT_READING', 'M2IO_NO_CURRENT_BLOCK', 'M2IO_DATA_NOT_FOUND', 'M2IO_ROW_INVALID', 'M2IO_NO_FULL_BLOCK', 'M2IO_NO_VALUE', ], [ 'MMALIGN_ERROR', 'MMALIGN_OK', 'MMALIGN_FATAL', 'MMALIGN_WARNING', 'MMALIGN_INFO', 'MMALIGN_DEBUG', ], [ 'MMASL_ERR', 'MMASL_OK', ], [ 'MMAT_ERR', 'MMAT_OK', ], [ 'MMBS_ERR', 'MMBS_OK', ], [ 'MMBUILD_ERROR', 'MMBUILD_OK', ], [ 'MMCANON_ERR', 'MMCANON_OK', ], [ 'MMCELL_FATAL', 'MMCELL_ERROR', 'MMCELL_WARNING', 'MMCELL_WARNING', 'MMCELL_INFO', 'MMCELL_DEBUG', 'MMCELL_OK' ], ['MMCOLOR_OK', 'MMCOLOR_ERROR'], [ 'MMCONF_OK', 'MMCONF_WARNING', 'MMCONF_ERR', 'MMCONF_EOF', 'MMCONF_PROBLEM', 'MMCONF_ERR_MOL_INFO', 'MMCONF_ERR_DIFFICULT_MOL', 'MMCONF_ERR_INPUT_CONF' ], [ 'MMCOMMON_ERROR', 'MMCOMMON_OK', ], [ 'MMCRYSTAL_ERROR', 'MMCRYSTAL_OK', ], [ 'MMCT_ERROR', 'MMCT_OK', 'MMCT_FATAL', 'MMCT_WARNING', 'MMCT_INFO', 'MMCT_DEBUG', ], [ 'MMERR_BUMMER', 'MMERR_OK', ], [ 'MMFEPIO_ERR', 'MMFEPIO_OK', ], [ 'MMFFIO_ERR', 'MMFFIO_OK', ], [ 'MMFFLD_ERR', 'MMFFLD_OK', ], [ 'MMFILE_ERROR', 'MMFILE_OK', ], [ 'MMFRAG_ERROR', 'MMFRAG_OK', 'MMFRAG_NOTFOUND', 'MMFRAG_DONE', 'MMFRAG_PROMPT', 'MMFRAG_GROW_BOND_NOT_FOUND', 'MMFRAG_TRUNCATION', ], [ 'MMHTREAT_ERROR', 'MMHTREAT_OK', ], [ 'MMIDEAL_ERROR', 'MMIDEAL_OK', 'MMIDEAL_FATAL', 'MMIDEAL_WARNING', 'MMIDEAL_INFO', ], [ 'MMIM_ERR', 'MMIM_OK', ], [ 'MMJAG_ERR', 'MMJAG_OK', ], [ 'MMKV_ERR', 'MMKV_OK', ], [ 'MMLEWIS_ERR', 'MMLEWIS_OK', ], [ 'MMLIST_ERR', 'MMLIST_OK', ], ['MMMDL_ERR', 'MMMDL_OK', 'MMMDL_EOF', 'MMMDL_NOSTRUCTURE'], [ 'MMMOL2_ERR', 'MMMOL2_OK', ], [ 'MMNEUT_ERR', 'MMNEUT_OK', ], [ 'MMPATTY_ERR', 'MMPATTY_OK', 'MMPATTY_INVALID_PATTERN', 'MMPATTY_CT_STARTED', ], [ 'MMPDB_EOF', 'MMPDB_ERR', 'MMPDB_OK', ], [ 'MMPKA_ERR', 'MMPKA_OK', 'MMPKA_WARNING', 'MMPKA_PROBLEM', 'MMPKA_FATAL', ], [ 'MMPREF_ERR', 'MMPREF_DUPLICATE_VALUE', 'MMPREF_NO_KEY', 'MMPREF_KEY_INVALID_CHAR', 'MMPREF_OK' ], [ 'MMROTAMER_ERROR', 'MMROTAMER_OK', ], [ 'MMSEQ_ERROR', 'MMSEQ_OK', 'MMSEQ_FATAL', 'MMSEQ_WARNING', 'MMSEQ_INFO', 'MMSEQ_DEBUG', ], [ 'MMSEQIO_ERROR', 'MMSEQIO_OK', 'MMSEQIO_EOF', ], [ 'MMSMILES_ERR', 'MMSMILES_OK', ], [ 'MMSMILESMAE_ERR', 'MMSMILESMAE_OK', ], [ 'MMSPG_FATAL', 'MMSPG_ERROR', 'MMSPG_WARNING', 'MMSPG_WARNING', 'MMSPG_INFO', 'MMSPG_DEBUG', 'MMSPG_OK' ], [ 'MMSS_ERROR', 'MMSS_OK', ], ['MMSTEREO_ERR', 'MMSTEREO_OK', 'MMSTEREO_EXTRA_BAD_CH_COMBO'], [ 'MMSUBS_ERR', 'MMSUBS_OK', 'MMSUBS_UNKNOWN_ATYPE', 'MMSUBS_UNBALANCED_PARENS', 'MMSUBS_UNKNOWN_BTYPE', 'MMSUBS_UNKNOWN_CHARGE', ], [ 'MMSUPER_ERROR', 'MMSUPER_OK', 'MMSUPER_ATOM_LIST_ERROR', 'MMSUPER_WARNING' ], [ 'MMSYM_ERROR', 'MMSYM_OK', ], [ 'MMSYS_SUCCESS', 'MMSYS_INFO_HOSTNAME', 'MMSYS_INFO_IPADDR', 'MMSYS_INFO_FQDN', 'MMSYS_INFO_DATE', 'MMSYS_INFO_NOHWADDR', 'MMSYS_INFO_MACHID', 'MMSYS_ERR_MAX', 'MMSYS_FAILURE' ], [ 'MMTABLE_ERROR', 'MMTABLE_OK', ], ['MMTAUT_ERR', 'MMTAUT_OK', 'MMTAUT_WARNING', 'MMTAUT_UNDEF'], [ 'MMTYPE_ERR', 'MMTYPE_OK', ], [ 'MMXDEN_OUTSIDE_BOUNDARY', 'MMXDEN_NO_ATOMS', 'MMXDEN_FATAL', 'MMXDEN_ERROR', 'MMXDEN_WARNING', 'MMXDEN_INFO', 'MMXDEN_DEBUG', 'MMXDEN_OK' ], [ 'MMZIP_ERROR', 'MMZIP_OK', ], [ 'RECAP_ERR', 'RECAP_OK', ], ] return_codes = mmcheck.generate_return_code_dict(pymmlibs.__dict__, mm_return_code_lists) # Set up some return code aliases for alternate prefixes. return_codes['mmctg'] = return_codes['mmct'] return_codes['canon'] = return_codes['mmcanon'] #mmsys and ligprep3 use non standard return codes, so add them separately return_codes['mmsys'].ok = getattr(pymmlibs, 'MMSYS_SUCCESS') return_codes['mmsys'].error = getattr(pymmlibs, 'MMSYS_FAILURE') return_codes['ligprep3'].ok = getattr(pymmlibs, 'LIGPREP3_SUCCESS') return_codes['ligprep3'].error = getattr(pymmlibs, 'LIGPREP3_FAILURE') # Functions that have underscores in their names but aren't mmlibs functions # that should be wrapped. _non_mm_functions = { "get_ligand_parameters", "get_localhost_temp_dir", "get_schrodinger_temp_dir", "set_ligand_parameters", 'DistanceCell_swigregister', 'LigandParameters_swigregister', 'LigandScoreStructure_swigregister', 'MMPKA_PKA_NAMES_swigregister', 'MMPREF_HANDLE_swigregister', 'MMPREF_swigregister', 'MMcrystal_SymOp_swigregister', 'MMjag_orbital_swigregister', 'MMtable_uitable_def_swigregister', 'PBC_swigregister', 'Preferences_swigregister', 'ScoreAtom_swigregister', 'WaterMapAtom_swigregister', 'WaterMapStructure_swigregister', } error_handler = pymmlibs.MMERR_DEFAULT_HANDLER # Note that importing this module checks out an MMLIBS license. This call to # _wrap_pymmlibs calls mmerr_initialize, which checks one out. mmcheck.wrap_module(pymmlibs.__dict__, return_codes, _non_mm_functions, _failure, inserted_module_globals=globals()) set_globals() MmException = mmcheck.MmException # __all__ is for inclusion in the Python documentation: __all__ = [e for e in dir() if not e.startswith(('_', 'Swig', 'SWIG'))]