Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,31 @@ per-contribution breakdown — currently trajectory averages (the one-shot

`multipole_model` does the expensive per-structure setup once and caches the
intermediate amplitudes; `model.intensity(volume_scale, contrast_density)` then
only applies the fit knobs — typically under a millisecond. There are two ways
to fit:
only applies the fit knobs — typically under a millisecond. Choose the fitting
method with the required `method` argument:

```python
import numpy as np
import pripps

# experimental data: q (Å⁻¹), I(q), σ(q)
q_exp, i_exp, sigma = np.loadtxt("experimental.dat", comments="#", unpack=True)

# (a) built-in fit — returns a typed FitResult:
fit = model.fit(q_exp, i_exp, sigma)
# (a) Nelder-Mead fit — returns a typed FitResult:
fit = model.fit(q_exp, i_exp, sigma, method="nelder-mead")
print(fit.volume_scale, fit.contrast_density, fit.chi2, fit.scale)

# (b) manual fit with scipy for full control:
# (b) exhaustive grid fit over the built-in bounds:
fit_grid = model.fit(q_exp, i_exp, sigma, method="grid",
c1_points=151, c2_points=101)
print(fit_grid.volume_scale, fit_grid.contrast_density, fit_grid.chi2)

# Change the grid-search box when needed:
fit_grid_wide = model.fit(q_exp, i_exp, sigma, method=pripps.FitMethod.Grid,
c2_bounds=(0.0, 2.0),
c1_points=151, c2_points=201)

# (c) manual fit with scipy for full control:
from scipy.optimize import minimize
def chi2(params):
out = model.intensity(*params)
Expand All @@ -103,7 +114,7 @@ discrete-q) accept the same solvent arguments and expose the same

A full working example is in `pripps-py/examples/fit_lysozyme.py`, which fits
lysozyme against the shipped `tests/lysozyme/lyzexp.dat` and reproduces FoXS's
χ²/N ≈ 0.20 (demonstrating both fitting styles):
χ²/N ≈ 0.20 (demonstrating both fitting methods):

```sh
python pripps-py/examples/fit_lysozyme.py
Expand Down Expand Up @@ -491,6 +502,10 @@ Output is CSV: `q,total` for vacuum, or
With `--fit`, output is `q,i_exp,i_fit,sigma` at experimental
q points. The experimental file is auto-detected as CSV or
whitespace-separated (3 columns: q, I, σ).
Use `--fit-method grid --fit-c1-points 151 --fit-c2-points 101`
to compare against an exhaustive grid search over the fit bounds.
Override the default bounds (`c₁ ∈ [0.5, 2.0]`, `c₂ ∈ [0.0, 0.1]`)
with `--fit-c1-bounds LOWER UPPER` and `--fit-c2-bounds LOWER UPPER`.

### GPU acceleration (`gpu` feature)

Expand Down
40 changes: 20 additions & 20 deletions assets/poly_amino_acid.csv
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
name,term,c0,c1,c2,c3,c4,c5,c6
ALA,formfactor,37.98651145079954,0.0,-17.88881261159881,-3.1097731825829333,8.846459092736989,-2.3572911188270753,0.05331786541354333
ALA,formfactor,38.0,0.0,-19.32016551855235,1.0234915749412843,4.451229286683712,-0.3263713521529865,-0.2909794345632165
ALA,excluded_solvent,29.045092626980807,0.0,-26.82743171578708,-1.9310977148566097,20.168431250949013,-10.337343031318388,1.6129945355732858
ARG,formfactor,83.96908927242093,0.0,-278.81910994314467,490.5059319443547,-383.9755997417938,143.65451627028935,-20.783481179736413
ARG,formfactor,84.0,0.0,-274.8059225122575,477.8230012497402,-369.932698700882,137.04536010789943,-19.654897755431197
ARG,excluded_solvent,61.48590421009381,0.0,-182.19421922046388,254.9995877714297,-162.0053689458599,51.021483900322494,-6.424772180212159
ASN,formfactor,59.98205560472268,0.0,-40.54214890095476,-32.39953367060282,73.4159357342896,-37.17064504604371,6.101333446616579
ASN,formfactor,60.0,0.0,-40.72187189239314,-32.00408094768902,73.04157294216571,-37.003149786191585,6.072647816866323
ASN,excluded_solvent,40.032910229163015,0.0,-43.419271616917506,-2.5096331414436257,37.78025696960391,-21.16604652006109,3.5704626997326017
ASP,formfactor,59.98252699985404,0.0,-37.42179690845112,-37.97031252961563,77.22160318216388,-38.25436485287656,6.198643717045879
ASP,formfactor,60.0,0.0,-37.53991974340553,-37.73432869645716,77.00289380738126,-38.1543068427208,6.18086524802638
ASP,excluded_solvent,38.84073261635539,0.0,-39.80757800147463,-6.1050880975993564,38.584033668906045,-20.838504513678572,3.448422193736537
CYS,formfactor,53.98471591625841,0.0,-28.55463591537983,-34.95759123047967,63.496177867671385,-29.839780719449596,4.609281628955767
CYS,formfactor,54.0,0.0,-28.62798769638874,-34.79734745323635,63.3307895320484,-29.759641931050375,4.594863941993998
CYS,excluded_solvent,35.50267070799075,0.0,-39.09278093395425,1.6989104594187223,28.01870291638898,-15.980070618028627,2.685602905744272
GLN,formfactor,68.00029704612041,0.0,-97.52724702286758,63.863879205326334,13.865971310987792,-22.96589467520148,5.296934807386833
GLN,formfactor,68.0,0.0,-101.98875841144464,76.79707183124806,-0.0547946062220936,-16.42825671863048,4.169636508145346
GLN,excluded_solvent,48.898600541821935,0.0,-77.65395265978444,40.54946712843443,18.936705440015086,-19.2453476844495,3.940784263263467
GLU,formfactor,68.00262098772043,0.0,-95.50455833177392,59.449715597229726,18.625430344038303,-25.334425917186397,5.722041637792017
GLU,formfactor,68.0,0.0,-99.88839536805934,72.1635296788336,4.933255563686118,-18.899238328449023,4.611423869188805
GLU,excluded_solvent,47.70649459960143,0.0,-72.13383592347742,32.19791380532419,24.30930931866937,-20.876834470726052,4.131360684537825
GLY,formfactor,29.99006405529222,0.0,-11.572242769967232,-0.9021293993630419,3.790951509543525,-0.7238332866526376,-0.05549468364095844
GLY,formfactor,30.0,0.0,-12.005751233227471,0.2948466618146197,2.5489770577885777,-0.1588312678254263,-0.15024573109140593
GLY,excluded_solvent,19.95957354188481,0.0,-14.596710882003759,-2.4650485889412432,10.550404760378463,-4.733006480429002,0.658871566636229
HIS,formfactor,71.99289906060545,0.0,-93.58672742143521,41.460338892548805,39.724339660983915,-34.41529003289915,7.057596750057414
HIS,formfactor,72.0,0.0,-98.97426210268725,57.555695671615055,22.097430820009727,-26.044582036430416,5.602190442905067
HIS,excluded_solvent,50.56476709188372,0.0,-88.00858173319708,57.29648278061343,8.364968725388358,-16.350312366132616,3.664942297923531
ILE,formfactor,61.97933054508859,0.0,-45.55749645626756,-26.94147636420316,68.41091746940783,-34.307325839550984,5.508363044131372
ILE,formfactor,62.0,0.0,-45.73485746693416,-26.574511174443753,68.08008685439722,-34.16436259460351,5.484442599766367
ILE,excluded_solvent,55.85191850939976,0.0,-81.76824367344963,25.9718149641765,39.09563612134737,-27.79407667749436,5.140594587619425
LEU,formfactor,61.9874112464829,0.0,-54.07829774966109,-19.672724727921118,75.75933357599484,-42.87909415253206,7.580643479500708
LEU,formfactor,62.0,0.0,-55.64554107949307,-15.195174888371744,70.949869654294,-40.60617679654624,7.184116830778993
LEU,excluded_solvent,55.85500702439895,0.0,-90.05823613360623,42.779271367948105,27.425314570778514,-24.599500988549345,4.878915346497919
LYS,formfactor,69.99129116923348,0.0,-177.94423757968704,272.0256856055207,-188.2920973172914,63.303038257186586,-8.32612812430321
LYS,formfactor,70.0,0.0,-180.66318232851853,279.4903377262558,-195.9396175726572,66.7466214366752,-8.89972948596301
LYS,excluded_solvent,59.73734011424962,0.0,-152.78437269984616,187.93704583787604,-102.44089786274051,27.188377002036162,-2.8320376302376786
MET,formfactor,70.00691278772638,0.0,-104.22345654704631,73.82601789465483,10.126507627913185,-23.351946238697035,5.598503080281802
MET,formfactor,70.0,0.0,-107.88006886632101,84.4290359916352,-1.3756663738244144,-17.88915729745889,4.645004029912363
MET,excluded_solvent,53.406398181964576,0.0,-110.88151801680236,100.05649928313625,-25.69528079121111,-3.5675976163339627,1.822892341875317
PHE,formfactor,77.99863587497389,0.0,-135.30506501839736,122.61728717372222,-26.829761151876106,-9.267313845762843,3.479368368324131
PHE,formfactor,78.0,0.0,-143.38043134543642,146.64317360927384,-52.80562355324896,2.8736007093054288,1.4027283832840152
PHE,excluded_solvent,68.93257004637968,0.0,-147.5670650614922,137.54078929479533,-39.12160207012098,-2.753466411358474,2.1427403561631735
PRO,formfactor,52.98008056903471,0.0,-28.025579140605455,-17.945632640349288,36.70484993598286,-16.388585233440434,2.3759607129713807
PRO,formfactor,53.0,0.0,-27.765272114009555,-18.82888037867656,37.702175858874234,-16.865801085294375,2.459160333093385
PRO,excluded_solvent,44.92171507351757,0.0,-48.596196051735205,-0.8750372245099269,38.16601448085936,-21.187997828228426,3.5216456896403727
SER,formfactor,45.98433274188738,0.0,-23.004358312306444,-13.52528557404974,25.318714967455264,-9.60754708227119,1.0838180112873488
SER,formfactor,46.0,0.0,-23.204949749810662,-13.009392289542262,24.783188342164642,-9.35839811914435,1.0408819422423707
SER,excluded_solvent,31.92723070377774,0.0,-28.914290210798498,-4.307301992955933,24.346605792144324,-12.176757238126978,1.8734369740555579
THR,formfactor,53.98079904257712,0.0,-30.205614210054552,-20.68857584136233,39.80321996161699,-16.614363714862087,2.188488144363049
THR,formfactor,54.0,0.0,-30.816156531523436,-18.992733253423083,38.02054022556375,-15.791867189461742,2.0486438454636606
THR,excluded_solvent,41.01359917184679,0.0,-45.25975736862446,1.4176217981309085,32.5646045063437,-18.24370055421664,3.0168424658285318
TRP,formfactor,98.00026950327825,0.0,-239.82185506986724,306.5877727946093,-164.7189974469082,39.67855896479587,-3.263270784166963
TRP,formfactor,98.0,0.0,-252.1252110603615,343.80177298471625,-205.29667620061204,58.71498335487439,-6.5218907212080515
TRP,excluded_solvent,82.45226706960327,0.0,-230.05660099986292,285.0669179531113,-150.2872276282459,36.63321998268637,-3.2505031840496486
TYR,formfactor,85.99025648157047,0.0,-205.8271529828311,282.4197901545501,-174.14171820412088,52.3398359916699,-6.16839805508144
TYR,formfactor,86.0,0.0,-208.72645876601825,291.2378555084771,-183.7899040486458,56.872904091917455,-6.944644812407045
TYR,excluded_solvent,71.89594546951952,0.0,-171.88553159706834,188.12775195681272,-82.8899246910726,14.785221706872576,-0.5321832521390917
VAL,formfactor,53.97802539665846,0.0,-30.730380715977926,-23.1259991191962,43.982242401804015,-18.76619704074442,2.5506887609142446
VAL,formfactor,54.0,0.0,-31.22062507236021,-21.80748875575384,42.61834256992178,-18.14265175796768,2.4452538649005087
VAL,excluded_solvent,46.99003082374464,0.0,-56.3441569003358,3.611267423393473,40.951469982336846,-23.894973751496867,4.06986224970413
Loading
Loading