-
Notifications
You must be signed in to change notification settings - Fork 48
Support for SAXS fitting (v2) #3786
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1aed392
started work on alternative saxs impl
klytje 0aaaa66
updated plugin generator
klytje 4f1d777
seems to work
klytje 5ff6333
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] 6b3a085
reverted unnecessary change
klytje 7e6e29d
change_calculation_type --> change_computation_type
klytje 11d14ce
modified 2D guard logic
klytje 7302bd8
updated pyausaxs to v1.0.9
klytje bd3ddc0
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] 8f53f2b
fixed ausaxs check for readiness
klytje bfbcf44
maybe tests passing now?
klytje 642cf67
added default ComputationType case
klytje 7ea6e6b
fixed file name mixup
klytje f9b2eaa
os-independent file names
klytje 77be836
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] edc4d55
simplified logic
klytje c4e8ae0
created common access point for base plugin name
klytje 606de0c
fixed exception message
klytje afa9f53
removed os import
klytje b118e06
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] 02363ba
fix ComputationType enum
klytje b0aa9bf
use posix paths
klytje d683f88
unpinned pyausaxs
klytje 3ae1d66
added error msg
klytje b655501
added explicit flag to preset for easy toggling
klytje e674c55
added another flag which could be relevant
klytje 84221d0
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] d70fa0d
Merge branch 'main' into saxs_fitting_v2
klytje File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ numpy | |
| packaging | ||
| periodictable | ||
| platformdirs | ||
| pyausaxs==1.0.4 | ||
| pyausaxs | ||
| pybind11 | ||
| pylint | ||
| pyopencl | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| from pathlib import Path | ||
|
|
||
| from sas.system.user import find_plugins_dir | ||
|
|
||
|
|
||
| def get_base_plugin_name() -> str: | ||
| """ | ||
| Get the base name for the AUSAXS SAXS plugin model. | ||
|
|
||
| :return: The base name of the plugin model. | ||
| """ | ||
|
|
||
| return "SAXS fit" | ||
|
|
||
| def write_plugin_model(structure_path: str): | ||
| """ | ||
| Write the AUSAXS SAXS plugin model to the plugins directory. | ||
| The current version will be overwritten if it exists. | ||
|
|
||
| :param structure_path: Path to the structure file to be used by the plugin. | ||
| """ | ||
|
|
||
| path = Path(find_plugins_dir()) / "ausaxs_saxs_plugin.py" | ||
| text = get_model_text(structure_path) | ||
| with open(path, 'w') as f: | ||
| f.write(text) | ||
|
|
||
| def get_model_text(structure_path: str) -> str: | ||
| """ | ||
| Generate the text of the AUSAXS SAXS plugin model. | ||
|
|
||
| :param structure_path: Path to the structure file to be used by the plugin. | ||
| :return: The text of the plugin model. | ||
| """ | ||
|
|
||
|
klytje marked this conversation as resolved.
|
||
| return ( | ||
| f'''\ | ||
| r""" | ||
| This file is auto-generated, and any changes will be overwritten. | ||
|
|
||
| This plugin model uses the AUSAXS library (https://doi.org/10.1107/S160057672500562X) to fit the provided SAXS data to the file: | ||
| * \"{structure_path}\" | ||
| If this is not the intended structure file, please regenerate the plugin model from the generic scattering calculator. | ||
| """ | ||
| ''' | ||
|
|
||
| f'''\ | ||
| name = "{get_base_plugin_name()} ({Path(structure_path).name.split('.')[0]})" | ||
| title = "AUSAXS" | ||
| description = "Structural validation using AUSAXS" | ||
| category = "plugin" | ||
| parameters = [ | ||
| # name, units, default, [min, max], type, description | ||
| ['c', '', 1, [0, 100], '', 'Solvent density'], | ||
| #['d', '', 1, [0, 2], '', 'Excluded volume parameter'] | ||
| ] | ||
|
|
||
| ### | ||
| import pyausaxs as ausaxs | ||
| ausaxs.settings.set(\"allow_unknown_atoms\", \"false\") | ||
| ausaxs.settings.set(\"allow_unknown_residues\", \"false\") | ||
|
|
||
| structure_path = "{str(Path(structure_path).as_posix())}" | ||
|
|
||
| def Iq(q, c): | ||
| # Initialize on first call to keep objects alive for function lifetime | ||
| if not hasattr(Iq, '_initialized'): | ||
| Iq._mol = ausaxs.create_molecule(structure_path) | ||
| Iq._mol.hydrate() | ||
| Iq._fitobj = ausaxs.manual_fit(Iq._mol) | ||
| Iq._initialized = True | ||
| return Iq._fitobj.evaluate([c], q) | ||
| Iq.vectorized = True | ||
| ''') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.