Code Monkey home page Code Monkey logo

chmpy's Introduction

CI DOI


chmpy logo

chmpy

A library for computational chemistry in python.
Documentation»
Report a bug · Request a new feature

chmpy supports handling molecules, crystals, Hirshfeld & promolecule density isosurfaces, spherical harmonic shape descriptors and much more...

Installation

Basic installation can be done through the python package manager pip:

pip install chmpy
# or to install directly from GitHub:
pip install git+https://github.com/peterspackman/chmpy.git

For development or modifications, install locally using pip:

pip install -e .

Features

While the library is intended to be flexible and make it easy to build complex pipelines or properties, the following is a brief summary of intended features:

  • Load crystal structures from .cif, .res, POSCAR files.
  • Evaluate promolecule and procrystal electron densities.
  • Easily generate Hirshfeld or promolecule isosurfaces and associated properties.
  • Easily generate spherical harmonic shape descriptors for atoms, molecules, or molecular fragments.
  • Efficiently calculate crystal slabs, periodic connectivity and more...
  • Automatic parallelization of some calculations using OpenMP (set the OMP_NUM_THREADS environment variable)

It should also serve as a simple, easy to read library for learning how to represent crystal structures, molecules etc. and evaluate scientifically relevant information quickly and efficiently using python.

Examples

Crystal structures and molecules

Loading a crystal structure from a CIF (.cif) or SHELX (.res) file, or a molecule from an XMOL (.xyz) file is straightforward:

from chmpy import Crystal, Molecule
c = Crystal.load("tests/acetic_acid.cif")
print(c)
# <Crystal C2H4O2 Pna2_1>
# Calculate the unique molecules in this crystal
c.symmetry_unique_molecules()
# [<Molecule: C2H4O2(2.12,1.15,0.97)>]
m = Molecule.load("tests/water.xyz")
print(m)
# <Molecule: H2O(-0.67,-0.00,0.01)>

Hirshfeld and promolecule density isosurfaces

Hirshfeld and promolecule density isosurfaces

Generation of surfaces with the default settings can be done with minimal hassle, simply by using the corresponding members of the Crystal class:

c = Crystal.load("tests/test_files/acetic_acid.cif")
# This will generate a high resolution surface
# for each symmetry unique molecule in the crystal
surfaces = c.hirshfeld_surfaces()
print(surfaces)
# [<trimesh.Trimesh(vertices.shape=(3598, 3), faces.shape=(7192, 3))>]
# We can generate lower resolution surfaces with the separation parameter
surfaces = c.hirshfeld_surfaces(separation=0.5)
print(surfaces)
# [<trimesh.Trimesh(vertices.shape=(584, 3), faces.shape=(1164, 3))>]
# Surfaces can be saved via trimesh, or a utility function provided in chmpy
from chmpy.util.mesh import save_mesh
save_mesh(surfaces[0], "acetic_acid.ply")

The resulting surface should look something like this when visualized:


Acetic acid

chmpy's People

Contributors

peterspackman avatar setchatuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chmpy's Issues

Spherical harmonic coefficients

@peterspackman
I asked my student @weiluntang89 to extract the spherical harmonics coefficients from chmpy so that we can reconstruct the surface shape. We did the following,

image

But the output does not make sense to us.
For a given l_max, the number of coefficients should be (l_max + 1)^2. Can you help?

Installation issues with pip

Hi Peter,

I was unsure why there's an import error for setuptools, even though separately (see end of the snippet code), import work just fine in this conda environment.

$ conda activate chmpypackage
$ pip install chmpy
Collecting chmpy
Using cached chmpy-1.0b4.tar.gz (7.5 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting Jinja2<4.0.0,>=3.1.2 (from chmpy)
Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting matplotlib<4.0.0,>=3.5.2 (from chmpy)
Downloading matplotlib-3.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.8 kB)
Collecting numpy<2.0,>=1.12 (from chmpy)
Downloading numpy-1.26.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 kB 2.2 MB/s eta 0:00:00
Collecting scipy<2.0.0,>=1.8.1 (from chmpy)
Downloading scipy-1.11.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.4/60.4 kB 6.3 MB/s eta 0:00:00
Collecting seaborn<0.12.0,>=0.11.2 (from chmpy)
Using cached seaborn-0.11.2-py3-none-any.whl (292 kB)
Collecting trimesh<4.0.0,>=3.12.9 (from chmpy)
Using cached trimesh-3.23.5-py3-none-any.whl.metadata (17 kB)
Collecting MarkupSafe>=2.0 (from Jinja2<4.0.0,>=3.1.2->chmpy)
Downloading MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.0 kB)
Collecting contourpy>=1.0.1 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Downloading contourpy-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.8 kB)
Collecting cycler>=0.10 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Using cached cycler-0.12.1-py3-none-any.whl.metadata (3.8 kB)
Collecting fonttools>=4.22.0 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Downloading fonttools-4.44.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (153 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 153.6/153.6 kB 15.2 MB/s eta 0:00:00
Collecting kiwisolver>=1.3.1 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Downloading kiwisolver-1.4.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.metadata (6.4 kB)
Collecting packaging>=20.0 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Using cached packaging-23.2-py3-none-any.whl.metadata (3.2 kB)
Collecting pillow>=8 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Downloading Pillow-10.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (9.5 kB)
Collecting pyparsing>=2.3.1 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Using cached pyparsing-3.1.1-py3-none-any.whl.metadata (5.1 kB)
Collecting python-dateutil>=2.7 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting importlib-resources>=3.2.0 (from matplotlib<4.0.0,>=3.5.2->chmpy)
Using cached importlib_resources-6.1.1-py3-none-any.whl.metadata (4.1 kB)
Collecting pandas>=0.23 (from seaborn<0.12.0,>=0.11.2->chmpy)
Downloading pandas-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (18 kB)
Collecting zipp>=3.1.0 (from importlib-resources>=3.2.0->matplotlib<4.0.0,>=3.5.2->chmpy)
Using cached zipp-3.17.0-py3-none-any.whl.metadata (3.7 kB)
Collecting pytz>=2020.1 (from pandas>=0.23->seaborn<0.12.0,>=0.11.2->chmpy)
Using cached pytz-2023.3.post1-py2.py3-none-any.whl.metadata (22 kB)
Collecting tzdata>=2022.1 (from pandas>=0.23->seaborn<0.12.0,>=0.11.2->chmpy)
Using cached tzdata-2023.3-py2.py3-none-any.whl (341 kB)
Collecting six>=1.5 (from python-dateutil>=2.7->matplotlib<4.0.0,>=3.5.2->chmpy)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Downloading matplotlib-3.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.6/11.6 MB 95.6 MB/s eta 0:00:00
Downloading numpy-1.26.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 97.2 MB/s eta 0:00:00
Downloading scipy-1.11.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (36.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 36.6/36.6 MB 68.5 MB/s eta 0:00:00
Using cached trimesh-3.23.5-py3-none-any.whl (685 kB)
Downloading contourpy-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (310 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 311.0/311.0 kB 28.6 MB/s eta 0:00:00
Using cached cycler-0.12.1-py3-none-any.whl (8.3 kB)
Downloading fonttools-4.44.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 93.0 MB/s eta 0:00:00
Using cached importlib_resources-6.1.1-py3-none-any.whl (33 kB)
Downloading kiwisolver-1.4.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 77.2 MB/s eta 0:00:00
Downloading MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Using cached packaging-23.2-py3-none-any.whl (53 kB)
Downloading pandas-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.3/12.3 MB 103.6 MB/s eta 0:00:00
Downloading Pillow-10.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.5/3.5 MB 92.9 MB/s eta 0:00:00
Using cached pyparsing-3.1.1-py3-none-any.whl (103 kB)
Using cached pytz-2023.3.post1-py2.py3-none-any.whl (502 kB)
Using cached zipp-3.17.0-py3-none-any.whl (7.4 kB)
Building wheels for collected packages: chmpy
Building wheel for chmpy (pyproject.toml) ... error
error: subprocess-exited-with-error

× Building wheel for chmpy (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [24 lines of output]
Traceback (most recent call last):
File "/tmp/pip-install-nyucsble/chmpy_ac4e494d0b88479c80794999f2c19fcb/build.py", line 1, in
import setuptools
ModuleNotFoundError: No module named 'setuptools'
Traceback (most recent call last):
File "/cluster/home/iyemperu/miniconda3/envs/chmpypackage/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in
main()
File "/cluster/home/iyemperu/miniconda3/envs/chmpypackage/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/cluster/home/iyemperu/miniconda3/envs/chmpypackage/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
return _build_backend().build_wheel(wheel_directory, config_settings,
File "/tmp/pip-build-env-au4ygtoi/overlay/lib/python3.9/site-packages/poetry/core/masonry/api.py", line 58, in build_wheel
return WheelBuilder.make_in(
File "/tmp/pip-build-env-au4ygtoi/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 88, in make_in
wb.build(target_dir=directory)
File "/tmp/pip-build-env-au4ygtoi/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 123, in build
self._build(zip_file)
File "/tmp/pip-build-env-au4ygtoi/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 172, in _build
self._run_build_script(self._package.build_script)
File "/tmp/pip-build-env-au4ygtoi/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 266, in _run_build_script
subprocess.check_call([self.executable.as_posix(), build_script])
File "/cluster/home/iyemperu/miniconda3/envs/chmpypackage/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/cluster/home/iyemperu/miniconda3/envs/chmpypackage/bin/python', 'build.py']' returned non-zero exit status 1.
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for chmpy
Failed to build chmpy
ERROR: Could not build wheels for chmpy, which is required to install pyproject.toml-based projects
WARNING: There was an error checking the latest version of pip.
$ python -c "import setuptools"
$

Regarding the installation

@peterspackman It is a nice tool. I am in the middle of learning how to use it. However, I came into several issues as follows,

1, I firstly met the following complaints,

>>> from chmpy import Crystal, Molecule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/qiangzhu/Desktop/github/chmpy/chmpy/__init__.py", line 1, in <module>
    from .crystal import Crystal, SpaceGroup, UnitCell
  File "/Users/qiangzhu/Desktop/github/chmpy/chmpy/crystal/__init__.py", line 9, in <module>
    from .crystal import Crystal
  File "/Users/qiangzhu/Desktop/github/chmpy/chmpy/crystal/crystal.py", line 15, in <module>
    from trimesh import Trimesh
ModuleNotFoundError: No module named 'trimesh'

This can be trivially solved by pip install trimesh. However, I am curious if you have a mechanism to list all required package during the installation. This will make life easier.

2, I tried to get the Hirschfield surface.

>>> from chmpy import Crystal, Molecule
>>> c = Crystal.load("tests/test_files/acetic_acid.cif")
>>> surfaces = c.hirshfeld_surfaces()
>>> from chmpy.util.mesh import save_mesh
>>> save_mesh(surfaces[0], "acetic_acid.ply")

How can I visualize it?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.