|
| 1 | +# GSAS-II - Crystallography Software Package |
| 2 | + |
| 3 | +GSAS-II is a comprehensive Python package for analysis of x-ray and neutron diffraction data, including single-crystal, powder, and time-of-flight data. It includes both GUI (wxPython) and scriptable interfaces, with compiled Fortran extensions for performance-critical computations. |
| 4 | + |
| 5 | +Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### Bootstrap and Build the Repository |
| 10 | +```bash |
| 11 | +# Install core build dependencies |
| 12 | +python -m pip install --upgrade pip setuptools wheel |
| 13 | +python -m pip install meson-python ninja numpy cython scipy pycifrw |
| 14 | + |
| 15 | +# Build the package (takes ~16 seconds, NEVER CANCEL, set timeout to 30+ minutes) |
| 16 | +python -m build -wnx --no-isolation |
| 17 | + |
| 18 | +# OR install in editable mode for development (takes ~12 seconds, NEVER CANCEL, set timeout to 30+ minutes) |
| 19 | +python -m pip install -e . --no-build-isolation |
| 20 | +``` |
| 21 | + |
| 22 | +### Install Optional Dependencies |
| 23 | +```bash |
| 24 | +# For GUI functionality |
| 25 | +python -m pip install wxpython matplotlib pyopengl |
| 26 | + |
| 27 | +# For additional features |
| 28 | +python -m pip install pillow h5py imageio requests gitpython pybaselines |
| 29 | + |
| 30 | +# For testing and development |
| 31 | +python -m pip install pytest nox |
| 32 | +``` |
| 33 | + |
| 34 | +### Run Tests |
| 35 | +```bash |
| 36 | +# Add compiled executables to PATH before running tests |
| 37 | +export PATH="$PATH:$(pwd)/build/cp312/sources" |
| 38 | + |
| 39 | +# Alternative: Copy executables to a location in PATH (one-time setup) |
| 40 | +# mkdir -p ~/.local/bin |
| 41 | +# cp build/cp312/sources/{LATTIC,convcell} ~/.local/bin/ |
| 42 | + |
| 43 | +# Run all tests (some require network connectivity, ~3-4 seconds for working tests) |
| 44 | +python -m pytest tests/ -v |
| 45 | + |
| 46 | +# Run specific test modules that work offline |
| 47 | +python -m pytest tests/test_lattice.py tests/test_nistlat.py tests/test_elm.py -v |
| 48 | + |
| 49 | +# Using nox for testing workflow |
| 50 | +python -m nox -s tests |
| 51 | +``` |
| 52 | + |
| 53 | +### Validation Scenarios |
| 54 | +Always run these validation steps after making changes: |
| 55 | + |
| 56 | +1. **Basic Import Test**: |
| 57 | + ```bash |
| 58 | + python -c "import GSASII; print('GSAS-II import successful')" |
| 59 | + ``` |
| 60 | + |
| 61 | +2. **Scriptable Interface Test**: |
| 62 | + ```bash |
| 63 | + python -c " |
| 64 | + import GSASII.GSASIIscriptable as G2sc |
| 65 | + gpx = G2sc.G2Project(newgpx='/tmp/test.gpx') |
| 66 | + print('GSASIIscriptable working correctly') |
| 67 | + " |
| 68 | + ``` |
| 69 | + |
| 70 | +3. **Binary Extensions Test**: |
| 71 | + ```bash |
| 72 | + python -c " |
| 73 | + import GSASII.GSASIIlattice as G2lat |
| 74 | + import GSASII.GSASIIspc as G2spc |
| 75 | + print('Compiled extensions working') |
| 76 | + " |
| 77 | + ``` |
| 78 | + |
| 79 | +4. **Run Core Functionality Tests**: |
| 80 | + ```bash |
| 81 | + export PATH="$PATH:$(pwd)/build/cp312/sources" |
| 82 | + python -m pytest tests/test_lattice.py::test_Brav -v |
| 83 | + ``` |
| 84 | + |
| 85 | +## Build System Details |
| 86 | + |
| 87 | +### Timing Expectations |
| 88 | +- **NEVER CANCEL**: Build takes ~16 seconds on typical hardware but may take up to 30 minutes on slower systems |
| 89 | +- **NEVER CANCEL**: Editable install takes ~12 seconds but may take up to 30 minutes |
| 90 | +- **NEVER CANCEL**: Test suite takes 3-4 seconds for working tests but up to 10 minutes with all tests |
| 91 | +- Set explicit timeouts of 30+ minutes for build commands and 15+ minutes for test commands |
| 92 | + |
| 93 | +### Build Architecture |
| 94 | +- Uses **meson** build system with **f2py** for Fortran compilation |
| 95 | +- Compiles Fortran extensions: pyspg, pydiffax, pypowder, pytexture, pack_f, histogram2d, unpack_cbf |
| 96 | +- Builds standalone executables: LATTIC, convcell |
| 97 | +- Requires gfortran compiler |
| 98 | + |
| 99 | +### Build Troubleshooting |
| 100 | +- If binaries are missing: run `python -m pip install -e . --no-build-isolation` |
| 101 | +- For PATH issues with executables: `export PATH="$PATH:$(pwd)/build/cp312/sources"` |
| 102 | +- Build output location: `./build/cp312/sources/` (for Python 3.12) |
| 103 | + |
| 104 | +## Running Applications |
| 105 | + |
| 106 | +### Scriptable Interface (Recommended for Development) |
| 107 | +```bash |
| 108 | +python -c " |
| 109 | +import GSASII.GSASIIscriptable as G2sc |
| 110 | +gpx = G2sc.G2Project(newgpx='project.gpx') |
| 111 | +# Add your GSAS-II scripting code here |
| 112 | +" |
| 113 | +``` |
| 114 | + |
| 115 | +### GUI Application |
| 116 | +```bash |
| 117 | +# Note: GUI requires display/X11 - will not work in headless environments |
| 118 | +python -m GSASII |
| 119 | +``` |
| 120 | + |
| 121 | +## Development Workflow |
| 122 | + |
| 123 | +### Linting and Code Quality |
| 124 | +```bash |
| 125 | +# Using nox (recommended) |
| 126 | +python -m nox -s lint # Pre-commit hooks and formatting |
| 127 | +python -m nox -s pylint # Static code analysis |
| 128 | + |
| 129 | +# Manual linting |
| 130 | +python -m pip install pre-commit |
| 131 | +pre-commit run --all-files |
| 132 | +``` |
| 133 | + |
| 134 | +### Documentation |
| 135 | +```bash |
| 136 | +# Build documentation |
| 137 | +python -m nox -s docs |
| 138 | + |
| 139 | +# Build and serve docs locally |
| 140 | +python -m nox -s docs -- --serve |
| 141 | +``` |
| 142 | + |
| 143 | +### Common Development Tasks |
| 144 | +Always validate changes by running: |
| 145 | +1. Build the package: `python -m build -wnx --no-isolation` |
| 146 | +2. Install in editable mode: `python -m pip install -e . --no-build-isolation` |
| 147 | +3. Add executables to PATH: `export PATH="$PATH:$(pwd)/build/cp312/sources"` |
| 148 | +4. Run working tests: `python -m pytest tests/test_lattice.py tests/test_elm.py -v` |
| 149 | +5. Test core functionality: Run the validation scenarios above |
| 150 | + |
| 151 | +## Troubleshooting |
| 152 | + |
| 153 | +### Common Issues |
| 154 | +- **"binary load error: pyspg not found"**: Run editable install to compile binaries |
| 155 | +- **"FileNotFoundError: 'LATTIC'"**: Add `./build/cp312/sources` to PATH |
| 156 | +- **Network connectivity test failures**: Normal in restricted environments, focus on offline tests |
| 157 | +- **wxPython GUI issues**: GUI requires display, use scriptable interface in headless environments |
| 158 | + |
| 159 | +### Dependencies Not Found |
| 160 | +Install the specific missing dependency: |
| 161 | +```bash |
| 162 | +# For seekpath k-vector functionality |
| 163 | +python -m pip install seekpath |
| 164 | + |
| 165 | +# For complete GUI experience |
| 166 | +python -m pip install wxpython matplotlib pyopengl pillow h5py |
| 167 | +``` |
| 168 | + |
| 169 | +## Key Projects in Codebase |
| 170 | + |
| 171 | +### Main Modules |
| 172 | +- **GSASII/**: Main package directory |
| 173 | + - **GSASIIscriptable.py**: Primary API for programmatic use |
| 174 | + - **GSASIIGUI.py**: Main GUI application entry point |
| 175 | + - **GSASIIdata.py**: Core data structures and file I/O |
| 176 | + - **GSASIImath.py**: Mathematical routines for crystallography |
| 177 | + - **GSASIIlattice.py**: Lattice parameter and space group operations |
| 178 | + - **GSASIIspc.py**: Space group and symmetry operations |
| 179 | + |
| 180 | +### Build Files |
| 181 | +- **meson.build**: Main build configuration |
| 182 | +- **sources/meson.build**: Fortran extension build configuration |
| 183 | +- **pyproject.toml**: Package metadata and dependencies |
| 184 | + |
| 185 | +### Testing |
| 186 | +- **tests/**: Self-contained test suite |
| 187 | + - **test_lattice.py**: Lattice and crystallography tests (always work offline) |
| 188 | + - **test_nistlat.py**: NIST lattice utility tests (require executables in PATH) |
| 189 | + - **test_scriptref.py**: Scripting interface integration tests |
| 190 | + |
| 191 | +### Documentation |
| 192 | +- **docs/**: Sphinx documentation source |
| 193 | +- **README.md**: Project overview and links |
| 194 | + |
| 195 | +Always check binary compilation status and add executables to PATH before running tests or using advanced functionality. |
0 commit comments