mooonpy.molspace.molspace module
- class mooonpy.molspace.molspace.Molspace(filename='', **kwargs)[source]
Bases:
objectInitializes 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
.dataTripos mol2 file
.mol2SYBL 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, per_atom_comment=False)[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
- build_old2new(mode='contiguous', offset=0, start=1, keep=None)[source]
Build an
(old2new, new2old)mapping for use withremap_ids().See
mooonpy.molspace.remap.build_old2new()for parameter details.
- combine(other, vect=None, move_mode='offset', offset_types=False, assign_clusters=True)[source]
Append
otherintoselfin place.other’s atom ids are shifted byself’s currentmax(atoms)so they don’t collide. Coordinates of the shifted copy are translated viaAtoms.move()before merging.- Parameters:
other (Molspace) – Molspace to append. Not mutated.
vect (tuple[float, float, float] or None) – Displacement applied to
otherbefore merging.Noneskips translation.move_mode (str) – Mode passed to
Atoms.move(). Defaults to'offset'.offset_types (bool) – If True,
other’s atom-type integers are shifted bymax(self.ff.masses)and the corresponding mass entries are merged intoself.ff.masseswith the shifted keys. This is needed when the two systems use unrelated type tables (e.g. combining raw monomers from independent atom_typing runs). For systems that already share the same FF (e.g. post-BRM data files), leave it False so types stay aligned.assign_clusters (bool) – Re-run cluster identification after merge.
- Returns:
The id offset applied to
other’s atom ids.- Return type:
int
- compute_BADI_by_type(periodicity='ppp', comp_bond=True, comp_angle=True, comp_dihedral=True, comp_improper=True)[source]
Apply this command mol.ff.has_type_labels = True or mol.add_type_labels(labels) To make dict keys type labels
- compute_pairs(cutoff, whitelist=None, blacklist=None, algorithm='DD_13', periodicity='ppp')[source]
Compute pairwise distances within cutoff between atoms
- contiguous(start=1)[source]
Renumber atoms
start..start+N-1in current insertion order, in place. Returns theold2newdict.
- copy(deepcopy=False)[source]
Return a fully independent copy of this Molspace (independence verified in
tests/test_molspace_copy.py).Factory classes and defaults are frozen at construction, so the copy references the SAME factory/lookup instances by design; all mutable state is rebuilt fresh.
- Parameters:
deepcopy (bool) – if True, use the
copy.deepcopyfallback (same result, ~6-8x slower; for cross-checking only).
- 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 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]]
- min_image_unwrap(changeimg=True)[source]
Make every molecule whole under the minimum-image convention, in place.
Walks each bonded cluster outward from the atom nearest the box center and shifts every neighbor to its minimum-image position relative to the atom it was reached from, so no bond spans more than half the box. Restricted- triclinic safe: the minimum image is taken in fractional space (consistent with
Atoms.wrap()), then converted back through the box h-matrix.- Parameters:
mol – Molspace modified in place (needs .atoms, .atoms.box, bonds).
changeimg – If True, update each shifted atom’s image flags so the canonical wrapped position is preserved (unwrapped = stored + h.image stays invariant;
Atoms.wrap()will still recover the cell).
- reachable(start_id, depth)[source]
Flat-set bond-graph reachability from
start_idup todepthbonds (inclusive ofstart_id). Thin wrapper aroundmooonpy.molspace.graph_theory.interface.find_reachable_neighbors().
- read_files(filename, dsect=['all'], steps=Ellipsis)[source]
Read files into Molspace Currently supports .data and .dump files.
- Parameters:
filename (str or Path) – path to file to read
dsect (list) – Sections of data file to read, see mooonpy.molspace._files_io.read_lmp_data for more details
steps (list or int) – Steps in dump file to read see mooonpy.molspace._files_io.read_lmp_dump for more details
- Returns:
Modifies self in-place if data or single step, returns dict if multiple steps
- Return type:
None or dict
- Example:
>>> from mooonpy import Molspace >>> MyPath = Path('Project/Monomers/DETDA.data') >>> mol = Molspace(MyPath, dsect=['all']) >>> MyPath2 = Path('Project/Monomers/DETDA.dump') >>> series = Molspace(MyPath2, steps=None)
- remap_ids(old2new)[source]
Renumber and/or slice atom ids in place using
old2new.Any current atom whose id is not a key in
old2newis dropped, along with any bond/angle/dihedral/improper entry that references it. Container Python identities and surviving per-atom/per-bond object identities are preserved. Seemooonpy.molspace.remap.
- slice(keep_ids, renumber=True)[source]
Drop every atom whose id is not in
keep_ids, in place. By default the surviving atoms are renumbered contiguously from 1. Returns theold2newdict.
- update_atoms(atoms, whitelist=None, blacklist=None, box=True)[source]
Map per atom information from other atoms instance to this molspace
- 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