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

Fix issue #553 #554

Merged
merged 13 commits into from
Feb 14, 2025
Merged
42 changes: 22 additions & 20 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@ jobs:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- name: Set up Python from Miniconda/conda
uses: conda-incubator/[email protected]
with:
miniconda-version: latest
channels: conda-forge,defaults
channel-priority: true
activate-environment: anaconda-client-env
python-version: ${{ matrix.python-version }}
- name: Install conda dependencies
run: |
printenv
conda install -y -c conda-forge python=${{ matrix.python-version }} "numpy>=1.23" "scipy>=1.12" "matplotlib>=3.8" "h5py>=3.5" "wxpython>=4.2" scikit-learn jupyter plotly pytest pytest-cov coverage
- name: Install xraylarch and other dependencies with pip
run: |
pip install ".[all]"
- name: Run test suite
run: |
cd tests
python -m pytest
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y xvfb
- name: Set up Python from Miniconda/conda
uses: conda-incubator/[email protected]
with:
miniconda-version: latest
channels: conda-forge,defaults
channel-priority: true
activate-environment: anaconda-client-env
python-version: ${{ matrix.python-version }}
- name: Install conda dependencies
run: |
printenv
conda install -y -c conda-forge python=${{ matrix.python-version }} "numpy>=1.23" "scipy>=1.12" "matplotlib>=3.8" "h5py>=3.5" "wxpython>=4.2" scikit-learn jupyter plotly pytest pytest-cov coverage
- name: Install xraylarch and other dependencies with pip
run: |
pip install ".[all]"
- name: Run test suite
run: pytest --xvfb-backend xvfb tests/
30 changes: 17 additions & 13 deletions larch/wxlib/cif_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def onGetFeff(self, event=None):

etitles.append(f'Cell Parameters (A, degrees): {", ".join(cell)}')
etitles.append(f'Cell Volume (A^3): {cif.cell_volume:.5f}')
etitles.append(f'Crystal Density (gr/cm^3): {cif.crystal_density:.5f}')
etitles.append(f'Crystal Density (gr/cm^3): {cif.crystal_density}')
etitles.append(f'Compound: {cif.compound}')

fefftext = cif2feffinp(cif.ciftext, catom, edge=edge, cluster_size=csize,
Expand Down Expand Up @@ -693,11 +693,12 @@ def onExportCIF(self, event=None):
fh.write(cc.ciftext)
self.write_message("Wrote CIF file %s" % path, 0)

def onImportCIF(self, event=None):
wildcard = 'CIF files (*.cif)|*.cif|All files (*.*)|*.*'
path = FileOpen(self, message='Open CIF File',
wildcard=wildcard, default_file='My.cif')
path = unixpath(path)
def onImportCIF(self, event=None, path=None):
if path is None:
wildcard = 'CIF files (*.cif)|*.cif|All files (*.*)|*.*'
path = FileOpen(self, message='Open CIF File',
wildcard=wildcard, default_file='My.cif')
path = unixpath(path)
if path is not None:
try:
cif_data = parse_cif_file(path)
Expand All @@ -722,13 +723,14 @@ def onImportCIF(self, event=None):
message = [f"Error displaying CIF File: {path}"]
ExceptionPopup(self, title, message)

def onImportFeff(self, event=None):
def onImportFeff(self, event=None, path=None):
if not self.with_feff:
return
wildcard = 'Feff input files (*.inp)|*.inp|All files (*.*)|*.*'
path = FileOpen(self, message='Open Feff Input File',
wildcard=wildcard, default_file='feff.inp')
path = unixpath(path)
if path is None:
wildcard = 'Feff input files (*.inp)|*.inp|All files (*.*)|*.*'
path = FileOpen(self, message='Open Feff Input File',
wildcard=wildcard, default_file='feff.inp')
path = unixpath(path)
if path is not None:
fefftext = None
fname = Path(path).name
Expand Down Expand Up @@ -848,13 +850,15 @@ def onClose(self, event=None):


class CIFViewer(LarchWxApp):
def __init__(self, filename=None, version_info=None, **kws):
def __init__(self, filename=None, version_info=None, with_feff=False, **kws):
self.filename = filename
self.with_feff = with_feff
LarchWxApp.__init__(self, version_info=version_info, **kws)

def createApp(self):
frame = CIFFrame(filename=self.filename,
version_info=self.version_info)
version_info=self.version_info,
with_feff=self.with_feff)
self.SetTopWindow(frame)
return True

Expand Down
22 changes: 12 additions & 10 deletions larch/wxlib/structure2feff_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def onRunFeff(self, event=None):
out = self.wids['feffout_text']
out.Clear()
out.SetInsertionPoint(0)
out.WriteText(f'########\n###\n# Run Feff in folder: {folder:s}\n')
out.WriteText(f'########\n###\n# Run Feff in folder: {self.folder:s}\n')
out.SetInsertionPoint(out.GetLastPosition())
out.WriteText('###\n########\n')
out.SetInsertionPoint(out.GetLastPosition())
Expand Down Expand Up @@ -377,10 +377,11 @@ def onExportStructure(self, event=None):
fh.write(cc['structure_text'])
self.write_message("Wrote structure file %s" % path, 0)

def onImportStructure(self, event=None):
wildcard = 'Strucuture files (*.cif/*.postcar/*.contcar/*.chgcar/*locpot/*.cssr)|*.cif;*.postcar;*.contcar;*.chgcar;*locpot;*.cssr|Molecule files (*.xyz/*.gjf/*.g03/*.g09/*.com/*.inp)|*.xyz;*.gjf;*.g03;*.g09;*.com;*.inp|All other files readable with Openbabel (*.*)|*.*'
path = FileOpen(self, message='Open Structure File',
wildcard=wildcard, default_file='My.cif')
def onImportStructure(self, event=None, path=None):
if path is None:
wildcard = 'Strucuture files (*.cif/*.postcar/*.contcar/*.chgcar/*locpot/*.cssr)|*.cif;*.postcar;*.contcar;*.chgcar;*locpot;*.cssr|Molecule files (*.xyz/*.gjf/*.g03/*.g09/*.com/*.inp)|*.xyz;*.gjf;*.g03;*.g09;*.com;*.inp|All other files readable with Openbabel (*.*)|*.*'
path = FileOpen(self, message='Open Structure File',
wildcard=wildcard, default_file='My.cif')

if path is not None:
fmt = path.split('.')[-1]
Expand Down Expand Up @@ -426,10 +427,11 @@ def onImportStructure(self, event=None):
i, p = self.get_nbpage('Structure Text')
self.nb.SetSelection(i)

def onImportFeff(self, event=None):
wildcard = 'Feff input files (*.inp)|*.inp|All files (*.*)|*.*'
path = FileOpen(self, message='Open Feff Input File',
wildcard=wildcard, default_file='feff.inp')
def onImportFeff(self, event=None, path=None):
if path is None:
wildcard = 'Feff input files (*.inp)|*.inp|All files (*.*)|*.*'
path = FileOpen(self, message='Open Feff Input File',
wildcard=wildcard, default_file='feff.inp')
if path is not None:
fefftext = None
fname = Path(path).name.replace('.inp', '_run')
Expand Down Expand Up @@ -511,7 +513,7 @@ def __init__(self, filename=None, version_info=None, **kws):

def createApp(self):
frame = Structure2FeffFrame(filename=self.filename,
version_info=self.version_info)
version_info=self.version_info)
self.SetTopWindow(frame)
return True

Expand Down
2 changes: 1 addition & 1 deletion larch/xrd/struct2xas.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def read_structure(self, file):
self.nframes = 1
self.cif = CifParser(self.file, occupancy_tolerance=10, site_tolerance=5e-3)
self.struct = Structure.from_file(self.file)
# self.struct = self.cif.parse_structures()[0] #: TODO
# self.struct = self.cif.parse_structures(primitive=False)[0] #: TODO
# self.struct = self.cif.get_structures()[0] #: DEPRECATED / NOT WORKING!
logger.debug("structure created from a CIF file")
elif self.file_ext == ".xyz":
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ doc =
dev =
pytest
pytest-cov
pytest-xvfb #: For GUI testing
coverage
build
pre-commit
Expand Down
16 changes: 11 additions & 5 deletions tests/test_athena_addgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
from pathlib import Path
from larch.io import read_ascii, AthenaProject

data_dir = Path(__file__).parent.parent / "examples" / "xafsdata"


def test_add_athena_group():
a = read_ascii('../examples/xafsdata/cu_10k.xmu')
b = read_ascii('../examples/xafsdata/cu_10k.xmu')
a = read_ascii(data_dir / "cu_10k.xmu")
b = read_ascii(data_dir / "cu_10k.xmu")
b.mutrans = b.mu[:]
b.filename = 'cu_10k_copy.xmu'
b.filename = "cu_10k_copy.xmu"
del b.mu

p = AthenaProject('x1.prj')
p = AthenaProject("x1.prj")
p.add_group(a)
p.add_group(b)
p.save()

# remove file after test
Path('x1.prj').unlink(missing_ok=True)
Path("x1.prj").unlink(missing_ok=True)


if __name__ == "__main__":
test_add_athena_group()
25 changes: 25 additions & 0 deletions tests/test_wxlib_cif_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
"""Test larch.wxlib.cif_browser"""

import sys, os
import pytest
from pathlib import Path
from larch.wxlib.cif_browser import CIFViewer

toppath = Path(__file__).parent.parent
structpath = toppath / "examples" / "structuredata" / "struct2xas"


@pytest.mark.skipif(os.name == "nt" and sys.version_info < (3,10), reason="fails for windows and python3.9")
def test_cif2feff():
cif_file = structpath / "ZnO_mp-2133.cif"
viewer = CIFViewer(with_feff=True)
frame = viewer.GetTopWindow()
frame.onImportCIF(path=cif_file.as_posix())
frame.onGetFeff()
frame.onRunFeff()
# viewer.MainLoop()


if __name__ == "__main__":
test_cif2feff()
23 changes: 23 additions & 0 deletions tests/test_wxlib_structure2feff_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python
"""Test larch.wxlib.structure2feff_browser"""

import pytest
from pathlib import Path
from larch.wxlib.structure2feff_browser import Structure2FeffViewer

toppath = Path(__file__).parent.parent
structpath = toppath / "examples" / "structuredata" / "struct2xas"


def test_structure2feff():
struct_file = structpath / "GaBr_single_frame.xyz"
viewer = Structure2FeffViewer()
frame = viewer.GetTopWindow()
frame.onImportStructure(path=struct_file.as_posix())
frame.onGetFeff()
frame.onRunFeff()
# viewer.MainLoop()


if __name__ == "__main__":
test_structure2feff()
Loading