Python Organic Crystal Simulation Environment (pyocse)
Python Organic Crystal Simulation Environment (pyocse) is a library designed for simulating organic crystals. It facilitates tasks like automated force field generation for CHARMM and handling crystal structures and molecules. The current stable version is 0.1.3, with releases being infrequent, primarily tied to significant feature additions and core updates.
Common errors
-
ModuleNotFoundError: No module named 'pyocse'
cause The `pyocse` library has not been installed in the active Python environment.fixRun `pip install pyocse` in your terminal to install the library. -
TypeError: Argument 'ase_atom' must be an ase.Atoms object, not NoneType
cause The constructor for `pyocse.data.Molecule` or `pyocse.crystal.Crystal` received `None` for an argument that explicitly expects an `ase.Atoms` object.fixEnsure that the `ase_atom` argument (or similar data input) is provided with a valid `ase.Atoms` instance, or an appropriate alternative like a SMILES string when allowed. -
AttributeError: 'Molecule' object has no attribute 'get_cell'
cause Attempting to call an `ase.Atoms` method (`get_cell` typically for crystals) directly on a `pyocse.data.Molecule` object, which does not directly expose all `ase` methods or may not have a cell attribute.fixTo use `ase`-specific methods or access crystal properties, retrieve the underlying `ase.Atoms` object via the `ase_atom` attribute (e.g., `my_molecule.ase_atom.get_cell()`) or ensure you are operating on a `Crystal` object.
Warnings
- breaking The API for automated force field generation was significantly reworked in v0.1.0. Scripts relying on pre-0.1.0 `pyocse.force_field` modules will likely require updates.
- gotcha PyOCSE objects (`Molecule`, `Crystal`) frequently wrap or convert `ase` and `pymatgen` objects. Direct methods from `ase.Atoms` or `pymatgen.Structure` may not be directly available on `pyocse` objects without explicitly accessing their `ase_atom` or `pymatgen_structure` attributes.
- gotcha Automated force field generation via `pyocse.force_field` often leverages external services, specifically CHARMM-GUI. This implies a dependency on internet connectivity and the stability/API of the external service, which is outside of `pyocse`'s direct control.
Install
-
pip install pyocse
Imports
- Molecule
from pyocse.data import Molecule
- Crystal
from pyocse.crystal import Crystal
- Builder
from pyocse.builder import Builder
- ForceField
from pyocse.force_field import ForceField
Quickstart
from pyocse.data import Molecule
from ase.build import molecule as ase_build_molecule
# Create an ASE Atoms object for water
h2o_ase = ase_build_molecule("H2O")
# Initialize a pyocse Molecule from the ASE object
mol_h2o = Molecule(ase_atom=h2o_ase, name="Water")
print(f"Molecule Name: {mol_h2o.name}")
print(f"Number of Atoms in pyocse Molecule: {len(mol_h2o.atoms)}")
print(f"Atom symbols: {[atom.symbol for atom in mol_h2o.atoms]}")
# Access the underlying ASE Atoms object for ASE-specific methods
if mol_h2o.ase_atom:
print(f"Positions of first atom (via ASE): {mol_h2o.ase_atom.get_positions()[0]}")
else:
print("Underlying ASE Atoms object not available.")