Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ASCII gaussian cube data GaussianCubeReader #5967

Merged
merged 91 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
2e42287
Add ASCII gaussian cube data `GaussianCubeReader`
tkoyama010 Apr 24, 2024
62c1c23
Rename gaussian.py -> examples/99-advanced/chemistry.py
tkoyama010 Apr 24, 2024
2154724
Delete m4_TotalDensity.cube
tkoyama010 Apr 24, 2024
e29a8a6
Update pyvista/core/utilities/__init__.py
tkoyama010 Apr 25, 2024
89662c6
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
e2a5cd3
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
aec3981
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 Apr 25, 2024
6afe8fb
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
9251f40
Merge branch 'feat/add-gaussian-cube-reader' of https://github.com/py…
tkoyama010 Apr 25, 2024
5da4c79
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
831ba6c
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
e01ec41
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
929270b
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
a350591
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
ac3eef0
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
39a64de
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
1231079
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
7003a15
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
31520c5
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
0b51987
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
03782c7
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
42b47f0
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
ae33600
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
eb62f09
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
ede2cf9
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
7d0e0ab
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
3033707
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
7bf2844
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 25, 2024
8a03964
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 26, 2024
a00c629
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 26, 2024
7fe1da1
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 27, 2024
7b90083
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 Apr 27, 2024
73d26b5
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 27, 2024
a6fcc9f
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 Apr 27, 2024
769449a
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 Apr 27, 2024
ca276dd
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 Apr 28, 2024
9a50007
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 Apr 29, 2024
42d3a47
Update pyvista/core/_vtk_core.py
tkoyama010 Apr 29, 2024
3d9332a
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
32f0eec
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
1b4ca71
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
3316ae2
Update test_imagedata_filters.py
tkoyama010 Apr 29, 2024
c70e7c7
Update image_data.py
tkoyama010 Apr 29, 2024
ed7157a
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
b2627bb
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
abcacd8
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
ad11b25
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
f1769ff
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
6ac1ea2
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
f55f53c
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
bb7d215
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
d8ebeff
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
fc3ca6c
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
677ca15
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
7bb7cfd
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
db253aa
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 29, 2024
9783db9
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 30, 2024
d1821d6
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 30, 2024
679a3a9
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 Apr 30, 2024
68cbbad
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 30, 2024
1e20a21
Update examples/99-advanced/chemistry.py
tkoyama010 Apr 30, 2024
1c9fb75
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 May 1, 2024
9fe6aad
Update examples/99-advanced/chemistry.py
tkoyama010 May 1, 2024
5422568
Update examples/99-advanced/chemistry.py
tkoyama010 May 1, 2024
2792ad0
Update examples/99-advanced/chemistry.py
tkoyama010 May 2, 2024
7d509f3
Update chemistry.py
tkoyama010 May 2, 2024
72bde84
Update examples/99-advanced/chemistry.py
tkoyama010 May 2, 2024
20c9f8a
Update examples/99-advanced/chemistry.py
tkoyama010 May 2, 2024
dac15e7
Update _vtk_core.py
tkoyama010 May 2, 2024
4b9e9f5
Delete examples/99-advanced/chemistry.py
tkoyama010 May 2, 2024
fa37ea5
Merge branch 'feat/add-gaussian-cube-reader' of github.com:pyvista/py…
tkoyama010 May 2, 2024
65d4391
Update pyvista/core/utilities/reader.py
tkoyama010 May 2, 2024
8e01f44
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 May 2, 2024
873a6fc
Update pyvista/examples/downloads.py
tkoyama010 May 2, 2024
8227836
Merge branch 'feat/add-gaussian-cube-reader' of github.com:pyvista/py…
tkoyama010 May 2, 2024
b1d03ae
Update pyvista/examples/downloads.py
tkoyama010 May 2, 2024
c3ed1bb
Update index.rst
tkoyama010 May 2, 2024
6570745
Update tests/core/test_reader.py
tkoyama010 May 2, 2024
72a1aae
Merge branch 'feat/add-gaussian-cube-reader' of github.com:pyvista/py…
tkoyama010 May 2, 2024
fd7c687
Update pyvista/core/utilities/reader.py
tkoyama010 May 2, 2024
d1ada27
Update pyvista/core/utilities/reader.py
tkoyama010 May 3, 2024
bff0d0b
Update pyvista/core/utilities/reader.py
tkoyama010 May 3, 2024
aac9478
Update pyvista/examples/downloads.py
tkoyama010 May 3, 2024
951ea2d
Apply suggestions from code review
tkoyama010 May 3, 2024
86d7505
Update reader.py
tkoyama010 May 5, 2024
0238a8d
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 May 5, 2024
f2072ea
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 May 5, 2024
10e0f54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 5, 2024
ea0e79f
Merge branch 'main' into feat/add-gaussian-cube-reader
tkoyama010 May 5, 2024
c11e836
Merge branch 'main' into feat/add-gaussian-cube-reader
pyvista-bot May 5, 2024
0033eff
Merge branch 'main' into feat/add-gaussian-cube-reader
pyvista-bot May 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/api/readers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Reader Classes
FLUENTCFFReader
FluentReader
GambitReader
GaussianCubeReader
GIFReader
GLTFReader
HDFReader
Expand Down
1 change: 1 addition & 0 deletions pyvista/core/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
FLUENTCFFReader,
FluentReader,
GambitReader,
GaussianCubeReader,
GIFReader,
GLTFReader,
HDFReader,
Expand Down
91 changes: 91 additions & 0 deletions pyvista/core/utilities/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def get_reader(filename, force_ext=None):
+----------------+---------------------------------------------+
| ``.cgns`` | :class:`pyvista.CGNSReader` |
+----------------+---------------------------------------------+
| ``.cube`` | :class:`pyvista.GaussianCubeReader` |
+----------------+---------------------------------------------+
| ``.dat`` | :class:`pyvista.TecplotReader` |
+----------------+---------------------------------------------+
| ``.dcm`` | :class:`pyvista.DICOMReader` |
Expand Down Expand Up @@ -2577,12 +2579,101 @@ class GambitReader(BaseReader):
_vtk_class_name = "vtkGAMBITReader"


class GaussianCubeReader(BaseReader):
"""GaussianCubeReader for .cube files.

Examples
--------
>>> import pyvista as pv
>>> from pyvista import examples

>>> filename = examples.download_m4_total_density(load=False)
>>> filename.split("/")[-1] # omit the path
'm4_TotalDensity.cube'

"""

_vtk_module_name = "vtkIOChemistry"
_vtk_class_name = "vtkGaussianCubeReader"

def read(self, grid: bool = True):
"""Read the file and return the output.

Parameters
----------
grid : bool, default: False
Output as a grid if ``True``, otherwise return the polydata.
"""
from pyvista.core.filters import _update_alg # avoid circular import

_update_alg(self.reader, progress_bar=self._progress_bar, message=self._progress_msg)
data = (
wrap(self.reader.GetGridOutput()) if grid else wrap(self.reader.GetOutputDataObject(0))
)
if data is None: # pragma: no cover
raise RuntimeError("File reader failed to read and/or produced no output.")
data._post_file_load_processing() # type: ignore[union-attr]

# check for any pyvista metadata
data._restore_metadata() # type: ignore[union-attr]
return data

@property
def hb_scale(self) -> float:
"""Get the scaling factor to compute bonds with hydrogen atoms.

Returns
-------
float
The scaling factor to compute bonds with hydrogen atoms.

"""
return self.reader.GetHBScale()

@hb_scale.setter
def hb_scale(self, hb_scale: float):
"""Set the scaling factor to compute bonds with hydrogen atoms.

Parameters
----------
hb_scale : float
The scaling factor to compute bonds with hydrogen atoms.

"""
self.reader.SetHBScale(hb_scale)

@property
def b_scale(self) -> float:
"""Get the scaling factor to compute bonds between non-hydrogen atoms.

Returns
-------
float
The scaling factor to compute bonds between non-hydrogen atoms.

"""
return self.reader.GetBScale()

@b_scale.setter
def b_scale(self, b_scale: float):
"""Set the scaling factor to compute bonds between non-hydrogen atoms.

Parameters
----------
b_scale : float
The scaling factor to compute bonds between non-hydrogen atoms.

"""
self.reader.SetBScale(b_scale)


CLASS_READERS = {
# Standard dataset readers:
'.bmp': BMPReader,
'.cas': FluentReader,
'.case': EnSightReader,
'.cgns': CGNSReader,
'.cube': GaussianCubeReader,
'.dat': TecplotReader,
'.dcm': DICOMReader,
'.dem': DEMReader,
Expand Down
52 changes: 52 additions & 0 deletions pyvista/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -7675,6 +7675,58 @@ def _dataset_room_cff_files_func():
_dataset_room_cff = _MultiFileDownloadableDatasetLoader(_dataset_room_cff_files_func)


def download_m4_total_density(load=True): # pragma: no cover
"""Download a total density dataset of the chemistry.

Parameters
----------
load : bool, default: True
Load the dataset after downloading it when ``True``. Set this
to ``False`` and only the filename will be returned.

Returns
-------
pyvista.ImageData | str
DataSet or filename depending on ``load``.

Examples
--------
>>> import pyvista as pv
>>> from pyvista import examples

>>> filename = examples.download_m4_total_density(load=False)
>>> reader = pv.get_reader(filename)
>>> reader.hb_scale = 1.1
>>> reader.b_scale = 10.0

>>> grid = reader.read()
>>> poly = reader.read(grid=False)

Add the outline and volume to the plotter.

>>> pl = pv.Plotter()
>>> outline = pl.add_mesh(grid.outline(), color="black")
>>> volume = pl.add_volume(grid)

Add atoms and bonds to the plotter.

>>> atoms = pl.add_mesh(poly.glyph(geom=pv.Sphere()), color="red")
>>> bonds = pl.add_mesh(poly.tube(), color="white")

>>> pl.show(cpos="zx")

.. seealso::

:ref:`M4 Total Density Dataset <m4_total_density_dataset>`
See this dataset in the Dataset Gallery for more info.

"""
return _download_dataset(_dataset_m4_total_density, load=load)


_dataset_m4_total_density = _SingleFileDownloadableDatasetLoader('m4_TotalDensity.cube')


def download_headsq(load=True): # pragma: no cover
"""Download the headsq dataset.

Expand Down
26 changes: 26 additions & 0 deletions tests/core/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,3 +1036,29 @@ def test_gambitreader():

mesh = reader.read()
assert all([mesh.n_points, mesh.n_cells])


@pytest.mark.skipif(
pv.vtk_version_info < (9, 1, 0),
reason="Requires VTK>=9.1.0 for a concrete GaussianCubeReader class.",
)
def test_gaussian_cubes_reader():
filename = examples.download_m4_total_density(load=False)
reader = pv.get_reader(filename)
assert isinstance(reader, pv.GaussianCubeReader)
assert reader.path == filename

hb_scale = 1.1
b_scale = 10.0
reader.hb_scale = hb_scale
reader.b_scale = b_scale
assert reader.hb_scale == hb_scale
assert reader.b_scale == b_scale

grid = reader.read(grid=True)
assert isinstance(grid, pv.ImageData)
assert all([grid.n_points, grid.n_cells])

poly = reader.read(grid=False)
assert isinstance(poly, pv.PolyData)
assert all([poly.n_points, poly.n_cells])