mooonpy package
- class mooonpy.Molspace(filename='', **kwargs)[source]
Bases:
object
Initializes a Molspace instance
- This class can be called via:
Full namespace syntax :
mooonpy.molspace.molspace.Molspace()
Aliased namespace syntax :
mooonpy.Molspace()
Initialization Parameters
- filenamestr, optional
An optional filename to read and initialize a Molspace() instance with molecular system information (e.g. atoms, bonds, force field parameters …). Supported file extensions:
LAMMPS datafile
.data
Tripos mol2 file
.mol2
SYBL mol file
.mol
If no filename is provided the Molspace instance will be generated with no molecular system information.
Attributes
- Nint
The order of the filter. For ‘bandpass’ and ‘bandstop’ filters, the resulting order of the final second-order sections (‘sos’) matrix is
2*N
, with N the number of biquad sections of the desired system.- Wnarray_like
The critical frequency or frequencies. For lowpass and highpass filters, Wn is a scalar; for bandpass and bandstop filters, Wn is a length-2 sequence.
Methods
- Nint
The order of the filter. For ‘bandpass’ and ‘bandstop’ filters, the resulting order of the final second-order sections (‘sos’) matrix is
2*N
, with N the number of biquad sections of the desired system.
- add_type_labels(labels)[source]
Adds type labels for atom types and use 1st instance for each BADI type label
could refactor the composition to a function somewhere
- bonds_from_distances(periodicity: str = 'ppp')[source]
Resets the bonds in a molecular system, based in interatomic distances and valences of atoms. The cutoff distances are set based on the summation of vdw radii per element involved in the bond. Each atom’s valence is respected (e.g. the maximum number of allowable bonded atoms to a carbon atom is 4).
- Example:
>>> import mooonpy >>> my_molecule = mooonpy.molspace('detda.data') >>> my_molecule.bonds_from_distances(periodicity='fff')
Note
Before using this command the element per-atom info and element per-mass info need to be updated by running “my_molecule.update_elements()”.
- Parameters:
periodicity (str) – Optional for setting the periodicity of the model, where f=fixed and p=periodic. Each position is a face (e.g. periodicity=’fpp’ is fixed on X-faces and periodic in Y- and Z-faces)
- Returns:
None
- Return type:
None
- compute_BADI_by_type(periodicity='ppp', comp_bond=True, comp_angle=True, comp_dihedral=True, comp_improper=True)[source]
- compute_pairs(cutoff, whitelist=None, blacklist=None, algorithm='DD_13', periodicity='ppp')[source]
Compute pairwise distances within cutoff between atoms
- find_rings(ring_sizes: tuple[int] = (3, 4, 5, 6, 7))[source]
Finds all rings in the current Molspace instance. The size of rings searched for is set in the in the ring_sizes parameter.
- Example:
>>> import mooonpy >>> my_molecule = mooonpy.molspace('detda.mol2') >>> rings = my_molecule.find_rings(ring_sizes=(3,4,5,6,7)) >>> print(rings) [(1, 2, 3, 4, 5, 6)]
Note
Each ring will be sorted in the order it was traversed in the graph and will be in the canonical form (e.g., canonical=(1,2,3) vs non_canonical=(2,3,1)).
- Parameters:
ring_sizes (tuple[int]) – Tuple containing ring sizes to search for in graph
- Returns:
rings
- Return type:
list[tuple[int]]
- update_elements(type2mass=None, type2element=None)[source]
Updates every per-atom .element attribute with the element type for that atom.
- Example:
>>> import mooonpy >>> my_molecule = mooonpy.molspace('detda.data') >>> my_molecule.update_elements()
Note
This will also update the per-mass .element attribute in ff.masses dictionary as well.
- Parameters:
type2mass (dict[int, float]) – Optional for setting the atom type to mass map (e.g. type2mass={1: 12.01115, 2: 1.008}). If not provided this will be generated from the masses section.
type2element (dict[int, str]) – Optional for setting the atom type to mass map (e.g. type2element={1: ‘C’, 2: ‘H’}). If not provided this will be generated from the masses section and interally defined periodic table.
- Returns:
None
- Return type:
None
- class mooonpy.Path(string: str | Path)[source]
Bases:
str
As computational scientists, half our jobs is file management and manipulation, the Path class contains several aliases for the os.path and glob.glob modules to make processing data easier. All mooonpy functions internally use this class for inputs of files or folders. Relevant strings are converted to path on entering functions
Examples
A copy of the code used in these examples is avalible in rootmooonpyexamplestoolspath_utilsexample_Path.py
- Basic Path Operations
>>> project_path = Path('Project/Data/Analysis') >>> filename = Path('results.txt') >>> full_path = project_path / filename >>> print(full_path) Project\Data\Analysis\results.txt >>> print(abs(full_path)) root\mooonpy\examples\tools\path_utils\Project\Data\Analysis\results.txt
- Path Parsing
>>> sample_path = Path('experiments/run_001/data.csv.gz') >>> print(sample_path.dir()) experiments\run_001 >>> print(sample_path.basename()) data.csv.gz >>> print(sample_path.root()) data.csv >>> print(sample_path.ext()) .gz
- Extension Manipulation
>>> data_file = Path('analysis/results.txt') >>> print(data_file.new_ext('.json')) analysis\results.json >>> print(data_file.new_ext('.txt.gz')) analysis\results.txt.gz
- File Existence
>>> current_file = Path(__file__) >>> fake_file = Path('nonexistent.txt') >>> print(bool(current_file)) True >>> print(bool(fake_file)) False
- Wildcard Matching
>>> txt_pattern = Path('temp_dir/*.txt') >>> print(txt_pattern.matches()) ['test1.txt', 'test2.txt'] >>> for file in Path('temp_dir/*'): ... print(file.basename()) data.csv readme.md test1.txt test2.txt
- Recent File Finding
>>> pattern = Path('temp_dir/*.txt') >>> print(pattern.recent()) newest_file.txt >>> print(pattern.recent(oldest=True)) old_file.txt
- Smart File Opening
>>> mypath = Path('data.txt') >>> with mypath.open('w') as f: ... f.write('Hello World') # Creates regular file >>> compressed_path = Path('data.txt.gz') >>> # compressed_path.open() would use gzip automatically # Would automatically handle gzip compression ** Absolute Path Conversion ** >>> rel_path = Path('data/file.txt') >>> print(abs(rel_path)) root\mooonpy\examples\tools\path_utils\data\file.txt
Todo
__truediv__ __bool__ __abs__ and __iter__ docstrings in config?
- basename() Path [source]
Split Path to filename and extention.
Alias for os.path.basename
- Returns:
Path of file
- Return type:
- Example:
>>> from mooonpy import Path >>> MyPath = Path('Project/Monomers/DETDA.mol') >>> print(MyPath.basename()) 'DETDA.mol'
- dir() Path [source]
Split Path to directory.
Alias for os.path.dirname.
- Returns:
Path to directory
- Return type:
- Example:
>>> from mooonpy import Path >>> MyPath = Path('Project/Monomers/DETDA.mol') >>> print(MyPath.dir()) 'Project\Monomers'
- ext() Path [source]
Split Path to just extention.
Alias for os.path.basename and os.path.splitext.
- Returns:
extention as Path
- Return type:
- Example:
>>> from mooonpy import Path >>> MyPath = Path('Project/Monomers/DETDA.mol') >>> print(MyPath.ext()) '.mol'
- matches(whitelist_ext=None, blacklist_ext=None) List[Path] [source]
Finds matching paths with a * (asterisk) wildcard character.
- Returns:
List of matching Paths
- Return type:
List[Path]
- Example:
>>> from mooonpy import Path >>> MyWildcard = Path('*.mol') >>> print(Path.matches(MyWildcard)) [Path('DETDA.mol'), Path('DEGBF.mol')]
- open(mode='r', encoding='utf-8')[source]
Open path with smart_open
- Parameters:
mode (str) – Open mode, usually ‘r’ or ‘a’
encoding (str) – File encoding
- Returns:
opened file as object
- Return type:
File Object
- Example:
>>> from mooonpy import Path >>> MyPath = Path('Project/Monomers/DETDA.mol') >>> MyFileObj = MyPath.open(mode='r')
- recent(oldest: bool = False) Path | None [source]
Find wildcard matches and return the Path of the most recently modified file.
- Parameters:
oldest (bool) – Reverses direction and finds least recently modified file.
- Returns:
Path of most recently modified file
- Return type:
- Example:
>>> from mooonpy import Path >>> MyWildcard = Path('Template_*.lmpmol') >>> print(Path.recent()) 'Template_1_v10_final_realthistime.lmpmol' >>> print(Path.recent(oldest=True)) 'Template_1.lmpmol'
- class mooonpy.Thermospace(**kwargs)[source]
Bases:
ColTable
Class to hold data found in LAMMPS logs. Data is organized into columns
- classmethod basic_read(file: Path | str, silence_error_line: bool = False) Thermospace [source]
- join_restart(restart, step_col='Step', restart_step_ind=0, this_step_ind=None)[source]
Appends data from a restarted thermospace to the current one. Uses (step_col, restart_step_ind) as the start of the appended section, and finds the last matching (step_col, this_step_ind) and overwrites after that
step_col is the column used for indexing, defaults to ‘Step’ but ‘v_Time’ may also be used
restart_step_ind = 0 uses 0th index step, and so on this_step_ind = None uses last matching value
Subpackages
- mooonpy.fitting package
- mooonpy.guis package
- mooonpy.molspace package
- Subpackages
- Submodules
- mooonpy.molspace.atom_styles module
- mooonpy.molspace.atoms module
- mooonpy.molspace.bonds_from_distances module
- mooonpy.molspace.box module
- mooonpy.molspace.distance module
- mooonpy.molspace.doc_examples module
- mooonpy.molspace.force_field module
- mooonpy.molspace.molspace module
Molspace
Molspace.add_type_labels()
Molspace.bonds_from_distances()
Molspace.compute_ADI()
Molspace.compute_BADI_by_type()
Molspace.compute_bond_length()
Molspace.compute_pairs()
Molspace.find_cumulative_neighs()
Molspace.find_rings()
Molspace.generate_graph()
Molspace.read_files()
Molspace.update_elements()
Molspace.write_files()
- mooonpy.molspace.periodic_table module
- mooonpy.molspace.topology module
- mooonpy.programs package
- mooonpy.thermospace package
- mooonpy.tools package
- Submodules
- mooonpy.tools.file_utils module
- mooonpy.tools.loop_utils module
- mooonpy.tools.math_utils module
- mooonpy.tools.misc_utils module
- mooonpy.tools.signals module
- mooonpy.tools.string_utils module
- mooonpy.tools.tables module
- Submodules
- mooonpy.xrdspace package