sciforge 0.0.3

A comprehensive scientific computing library in pure Rust with zero dependencies
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
//! Dispatch handler for biophysics functions.

use super::super::params::*;
use crate::hub::domain::biology as bio;
use crate::hub::domain::common::errors::{HubError, HubResult};
use crate::hub::engine::experience::runner::RunOutput;

pub(super) fn dispatch(func: &str, p: &Params) -> HubResult<RunOutput> {
    match func {
        "membrane_bending_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::membrane_bending_energy(
                get_f(p, "kappa")?,
                get_f(p, "curvature")?,
                get_f(p, "spontaneous_curvature")?,
            ),
        )),
        "helfrich_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::helfrich_energy(
                get_f(p, "kappa")?,
                get_f(p, "kappa_bar")?,
                get_f(p, "c1")?,
                get_f(p, "c2")?,
                get_f(p, "c0")?,
            ),
        )),
        "membrane_tension" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::membrane_tension(
                get_f(p, "area_strain")?,
                get_f(p, "stretch_modulus")?,
            ),
        )),
        "lipid_diffusion_saffman_delbruck" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::lipid_diffusion_saffman_delbruck(
                get_f(p, "viscosity_membrane")?,
                get_f(p, "viscosity_water")?,
                get_f(p, "membrane_thickness")?,
                get_f(p, "radius")?,
                get_f(p, "t")?,
            ),
        )),
        "osmotic_lysis_threshold" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::osmotic_lysis_threshold(
                get_f(p, "internal_osmolarity")?,
                get_f(p, "membrane_tension_max")?,
                get_f(p, "radius")?,
            ),
        )),
        "vesicle_budding_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::vesicle_budding_energy(
                get_f(p, "kappa")?,
                get_f(p, "radius")?,
            ),
        )),
        "flip_flop_rate" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::flip_flop_rate(
                get_f(p, "activation_energy")?,
                get_f(p, "t")?,
            ),
        )),
        "lateral_pressure_profile" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::lateral_pressure_profile(
                get_f(p, "depth")?,
                get_f(p, "head_pressure")?,
                get_f(p, "tail_pressure")?,
                get_f(p, "thickness")?,
            ),
        )),
        "line_tension_domain" => Ok(RunOutput::Scalar(
            bio::biophysics::membrane::line_tension_domain(
                get_f(p, "length")?,
                get_f(p, "lambda")?,
            ),
        )),
        "lennard_jones" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::lennard_jones(
                get_f(p, "r")?,
                get_f(p, "epsilon")?,
                get_f(p, "sigma")?,
            ),
        )),
        "lennard_jones_force" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::lennard_jones_force(
                get_f(p, "r")?,
                get_f(p, "epsilon")?,
                get_f(p, "sigma")?,
            ),
        )),
        "biophys_coulomb_interaction" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::coulomb_interaction(
                get_f(p, "q1")?,
                get_f(p, "q2")?,
                get_f(p, "r")?,
                get_f(p, "epsilon_r")?,
            ),
        )),
        "debye_huckel" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::debye_huckel(
                get_f(p, "q")?,
                get_f(p, "r")?,
                get_f(p, "kappa")?,
                get_f(p, "epsilon_r")?,
            ),
        )),
        "kinetic_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::kinetic_energy(
                get_v(p, "velocities")?,
                get_v(p, "masses")?,
            ),
        )),
        "temperature_from_ke" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::temperature_from_ke(
                get_f(p, "ke")?,
                get_u(p, "n_particles")?,
                get_u(p, "n_dim")?,
            ),
        )),
        "morse_potential" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::morse_potential(
                get_f(p, "r")?,
                get_f(p, "d_e")?,
                get_f(p, "a")?,
                get_f(p, "r_e")?,
            ),
        )),
        "harmonic_bond" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::harmonic_bond(
                get_f(p, "r")?,
                get_f(p, "k")?,
                get_f(p, "r0")?,
            ),
        )),
        "harmonic_angle" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::harmonic_angle(
                get_f(p, "theta")?,
                get_f(p, "k")?,
                get_f(p, "theta0")?,
            ),
        )),
        "dihedral_potential" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::dihedral_potential(
                get_f(p, "phi")?,
                get_f(p, "k")?,
                get_f(p, "n")?,
                get_f(p, "delta")?,
            ),
        )),
        "nose_hoover_friction" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::nose_hoover_friction(
                get_f(p, "ke")?,
                get_f(p, "target_ke")?,
                get_f(p, "q")?,
            ),
        )),
        "switching_function" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::switching_function(
                get_f(p, "r")?,
                get_f(p, "r_on")?,
                get_f(p, "r_off")?,
            ),
        )),
        "pair_correlation_bin" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::pair_correlation_bin(
                get_v(p, "distances")?,
                get_f(p, "r_min")?,
                get_f(p, "r_max")?,
                get_u(p, "n_particles")?,
                get_f(p, "volume")?,
            ),
        )),
        "pressure_virial" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::pressure_virial(
                get_u(p, "n")?,
                get_f(p, "volume")?,
                get_f(p, "temperature")?,
                get_f(p, "virial_sum")?,
            ),
        )),
        "mean_free_path" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::mean_free_path(
                get_f(p, "density")?,
                get_f(p, "cross_section")?,
            ),
        )),
        "born_mayer_repulsion" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::born_mayer_repulsion(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "r")?,
            ),
        )),
        "buckingham_potential" => Ok(RunOutput::Scalar(
            bio::biophysics::molecular_dynamics::buckingham_potential(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "c")?,
                get_f(p, "r")?,
            ),
        )),
        "worm_like_chain" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::worm_like_chain(
                get_f(p, "l")?,
                get_f(p, "lp")?,
                get_f(p, "lc")?,
            ),
        )),
        "freely_jointed_chain" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::freely_jointed_chain(
                get_f(p, "l")?,
                get_u(p, "n")?,
                get_f(p, "b")?,
            ),
        )),
        "end_to_end_distance_rms" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::end_to_end_distance_rms(get_u(p, "n")?, get_f(p, "b")?),
        )),
        "biophys_radius_of_gyration" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::radius_of_gyration(get_u(p, "n")?, get_f(p, "b")?),
        )),
        "persistence_length_from_tangent" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::persistence_length_from_tangent(
                get_f(p, "cos_theta")?,
                get_f(p, "segment_length")?,
            ),
        )),
        "kratky_porod_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::kratky_porod_energy(
                get_f(p, "kappa")?,
                get_f(p, "ds")?,
                get_f(p, "curvature")?,
            ),
        )),
        "dna_twist_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::dna_twist_energy(
                get_f(p, "c_twist")?,
                get_f(p, "delta_twist")?,
                get_f(p, "length")?,
            ),
        )),
        "stokes_einstein_diffusion" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::stokes_einstein_diffusion(
                get_f(p, "t")?,
                get_f(p, "viscosity")?,
                get_f(p, "radius")?,
            ),
        )),
        "mean_squared_displacement" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::mean_squared_displacement(
                get_f(p, "d")?,
                get_f(p, "t")?,
                get_u(p, "n_dim")?,
            ),
        )),
        "sedimentation_coefficient" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::sedimentation_coefficient(
                get_f(p, "mass")?,
                get_f(p, "partial_specific_vol")?,
                get_f(p, "rho_solvent")?,
                get_f(p, "friction")?,
            ),
        )),
        "flory_radius" => Ok(RunOutput::Scalar(bio::biophysics::polymers::flory_radius(
            get_u(p, "n")?,
            get_f(p, "b")?,
            get_f(p, "nu")?,
        ))),
        "kuhn_length" => Ok(RunOutput::Scalar(bio::biophysics::polymers::kuhn_length(
            get_f(p, "persistence_length")?,
        ))),
        "contour_length" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::contour_length(get_u(p, "n")?, get_f(p, "b")?),
        )),
        "extensible_wlc" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::extensible_wlc(
                get_f(p, "force")?,
                get_f(p, "lp")?,
                get_f(p, "lc")?,
                get_f(p, "stretch_modulus")?,
                get_f(p, "t")?,
            ),
        )),
        "odijk_deflection_length" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::odijk_deflection_length(get_f(p, "lp")?, get_f(p, "d")?),
        )),
        "blob_size" => Ok(RunOutput::Scalar(bio::biophysics::polymers::blob_size(
            get_f(p, "kbt")?,
            get_f(p, "force")?,
        ))),
        "zimm_relaxation_time" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::zimm_relaxation_time(
                get_f(p, "viscosity")?,
                get_f(p, "rg")?,
                get_f(p, "kbt")?,
            ),
        )),
        "rouse_relaxation_time" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::rouse_relaxation_time(
                get_f(p, "friction")?,
                get_u(p, "n")?,
                get_f(p, "b")?,
                get_f(p, "kbt")?,
            ),
        )),
        "intrinsic_viscosity" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::intrinsic_viscosity(get_f(p, "rg")?, get_f(p, "mw")?),
        )),
        "overlap_concentration" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::overlap_concentration(get_f(p, "mw")?, get_f(p, "rg")?),
        )),
        "debye_scattering" => Ok(RunOutput::Scalar(
            bio::biophysics::polymers::debye_scattering(get_f(p, "q")?, get_f(p, "rg")?),
        )),
        "biophys_ramachandran_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::ramachandran_energy(get_f(p, "phi")?, get_f(p, "psi")?),
        )),
        "hydrophobic_free_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::hydrophobic_free_energy(
                get_f(p, "sasa_nonpolar")?,
                get_f(p, "gamma")?,
            ),
        )),
        "biophys_hydrogen_bond_energy" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::hydrogen_bond_energy(
                get_f(p, "r")?,
                get_f(p, "theta")?,
                get_f(p, "epsilon")?,
                get_f(p, "r0")?,
            ),
        )),
        "electrostatic_solvation" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::electrostatic_solvation(
                get_f(p, "charge")?,
                get_f(p, "radius")?,
                get_f(p, "epsilon_solvent")?,
            ),
        )),
        "fold_stability" => Ok(RunOutput::Scalar(bio::biophysics::protein::fold_stability(
            get_f(p, "delta_h")?,
            get_f(p, "delta_s")?,
            get_f(p, "delta_cp")?,
            get_f(p, "t")?,
            get_f(p, "t_ref")?,
        ))),
        "fraction_folded" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::fraction_folded(get_f(p, "delta_g")?, get_f(p, "t")?),
        )),
        "two_state_folding_rate" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::two_state_folding_rate(
                get_f(p, "k0")?,
                get_f(p, "delta_g_dagger")?,
                get_f(p, "t")?,
            ),
        )),
        "zimm_bragg_helix_coil" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::zimm_bragg_helix_coil(
                get_f(p, "s")?,
                get_f(p, "sigma")?,
                get_u(p, "n")?,
            ),
        )),
        "phi_value" => Ok(RunOutput::Scalar(bio::biophysics::protein::phi_value(
            get_f(p, "delta_g_mut_folding")?,
            get_f(p, "delta_g_wt_folding")?,
            get_f(p, "delta_g_mut_ts")?,
            get_f(p, "delta_g_wt_ts")?,
        ))),
        "kauzmann_hydrophobic" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::kauzmann_hydrophobic(
                get_f(p, "delta_cp")?,
                get_f(p, "t")?,
                get_f(p, "t_s")?,
                get_f(p, "t_h")?,
                get_f(p, "delta_h_h")?,
            ),
        )),
        "native_contact_fraction" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::native_contact_fraction(
                get_v(p, "current_distances")?,
                get_v(p, "native_distances")?,
                get_f(p, "cutoff")?,
            ),
        )),
        "denaturation_midpoint" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::denaturation_midpoint(
                get_f(p, "delta_h")?,
                get_f(p, "delta_s")?,
            ),
        )),
        "chevron_plot_folding" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::chevron_plot_folding(
                get_f(p, "k_f_water")?,
                get_f(p, "m_f")?,
                get_f(p, "denaturant")?,
            ),
        )),
        "chevron_plot_unfolding" => Ok(RunOutput::Scalar(
            bio::biophysics::protein::chevron_plot_unfolding(
                get_f(p, "k_u_water")?,
                get_f(p, "m_u")?,
                get_f(p, "denaturant")?,
            ),
        )),
        "optical_trap_force" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::optical_trap_force(
                get_f(p, "laser_power")?,
                get_f(p, "n_medium")?,
                get_f(p, "trap_efficiency")?,
            ),
        )),
        "fret_efficiency" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::fret_efficiency(get_f(p, "r")?, get_f(p, "r0")?),
        )),
        "fret_distance" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::fret_distance(
                get_f(p, "efficiency")?,
                get_f(p, "r0")?,
            ),
        )),
        "fluorescence_lifetime" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::fluorescence_lifetime(
                get_f(p, "quantum_yield")?,
                get_f(p, "radiative_rate")?,
            ),
        )),
        "photobleaching_rate" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::photobleaching_rate(
                get_f(p, "intensity")?,
                get_f(p, "cross_section")?,
                get_f(p, "quantum_yield_bleach")?,
            ),
        )),
        "fluorescence_recovery_half_time" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::fluorescence_recovery_half_time(
                get_f(p, "beam_radius")?,
                get_f(p, "diffusion_coeff")?,
            ),
        )),
        "single_molecule_diffusion_msd" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::single_molecule_diffusion_msd(
                get_f(p, "d")?,
                get_f(p, "t")?,
                get_f(p, "localization_error")?,
            ),
        )),
        "afm_cantilever_force" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::afm_cantilever_force(
                get_f(p, "spring_constant")?,
                get_f(p, "deflection")?,
            ),
        )),
        "hertz_contact_indentation" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::hertz_contact_indentation(
                get_f(p, "force")?,
                get_f(p, "radius")?,
                get_f(p, "youngs_modulus")?,
                get_f(p, "poisson")?,
            ),
        )),
        "micropipette_aspiration_tension" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::micropipette_aspiration_tension(
                get_f(p, "pressure")?,
                get_f(p, "pipette_radius")?,
            ),
        )),
        "youngs_modulus_from_hertz" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::youngs_modulus_from_hertz(
                get_f(p, "force")?,
                get_f(p, "indentation")?,
                get_f(p, "tip_radius")?,
                get_f(p, "poisson")?,
            ),
        )),
        "traction_force" => Ok(RunOutput::Scalar(
            bio::biophysics::single_molecule::traction_force(
                get_f(p, "displacement")?,
                get_f(p, "substrate_stiffness")?,
            ),
        )),
        "contact_order" => {
            let v = get_v(p, "contacts")?;
            let contacts: Vec<(usize, usize)> = v
                .chunks(2)
                .map(|c| (c[0] as usize, c[1] as usize))
                .collect();
            Ok(RunOutput::Scalar(bio::biophysics::protein::contact_order(
                &contacts,
                get_u(p, "chain_length")?,
            )))
        }
        "go_model_energy" => {
            let v = get_v(p, "contacts")?;
            let contacts: Vec<(usize, usize)> = v
                .chunks(2)
                .map(|c| (c[0] as usize, c[1] as usize))
                .collect();
            Ok(RunOutput::Scalar(
                bio::biophysics::protein::go_model_energy(
                    &contacts,
                    get_v(p, "distances")?,
                    get_v(p, "native_distances")?,
                    get_f(p, "epsilon")?,
                ),
            ))
        }
        "radius_of_gyration_3d" => {
            let v = get_v(p, "coords")?;
            let coords: Vec<(f64, f64, f64)> = v.chunks(3).map(|c| (c[0], c[1], c[2])).collect();
            Ok(RunOutput::Scalar(
                bio::biophysics::protein::radius_of_gyration_3d(&coords),
            ))
        }
        "verlet_step" => {
            let mut pos = get_v(p, "positions")?.to_vec();
            let mut vel = get_v(p, "velocities")?.to_vec();
            let forces = get_v(p, "forces")?;
            let masses = get_v(p, "masses")?;
            bio::biophysics::molecular_dynamics::verlet_step(
                &mut pos,
                &mut vel,
                forces,
                masses,
                get_f(p, "dt")?,
            );
            let mut out = pos;
            out.extend(vel);
            Ok(RunOutput::Vector(out))
        }
        "velocity_verlet_step" => {
            let mut pos = get_v(p, "positions")?.to_vec();
            let mut vel = get_v(p, "velocities")?.to_vec();
            let fo = get_v(p, "forces_old")?;
            let fn_ = get_v(p, "forces_new")?;
            let masses = get_v(p, "masses")?;
            bio::biophysics::molecular_dynamics::velocity_verlet_step(
                &mut pos,
                &mut vel,
                fo,
                fn_,
                masses,
                get_f(p, "dt")?,
            );
            let mut out = pos;
            out.extend(vel);
            Ok(RunOutput::Vector(out))
        }
        "berendsen_thermostat" => {
            let mut vel = get_v(p, "velocities")?.to_vec();
            bio::biophysics::molecular_dynamics::berendsen_thermostat(
                &mut vel,
                get_f(p, "current_temp")?,
                get_f(p, "target_temp")?,
                get_f(p, "tau")?,
                get_f(p, "dt")?,
            );
            Ok(RunOutput::Vector(vel))
        }
        _ => Err(HubError::InvalidInput(format!("unknown function: {func}"))),
    }
}