mythos.observables.membrane_melting_temp ======================================== .. py:module:: mythos.observables.membrane_melting_temp .. autoapi-nested-parse:: Membrane melting temperature observable. Computes the melting temperature (Tm) of a lipid membrane by fitting a sigmoid to area-per-lipid (APL) vs. temperature data, following the approach from jax-martini. The sigmoid model is: .. math:: \text{APL}(T) = \text{apl}_0 + c_{pg} \cdot T + \frac{\Delta\text{APL}}{1 + \exp(-k (T - T_m))} The five fit parameters are ``[apl0, c_p_g, dAPL, k, Tm]``. The module provides both standalone functions for sigmoid fitting and a :class:`MembraneMeltingTemp` observable class that takes a :class:`~mythos.simulators.io.SimulatorTrajectory` as input. Classes ------- .. autoapisummary:: mythos.observables.membrane_melting_temp.MembraneMeltingTemp Functions --------- .. autoapisummary:: mythos.observables.membrane_melting_temp.calculate_apl mythos.observables.membrane_melting_temp.apl_residual mythos.observables.membrane_melting_temp.get_initial_guess mythos.observables.membrane_melting_temp.fit_apl_sigmoid mythos.observables.membrane_melting_temp.compute_membrane_tm Module Contents --------------- .. py:function:: calculate_apl(t: jax.numpy.ndarray, apl0: float, c_p_g: float, dAPL: float, k: float, Tm: float) -> jax.numpy.ndarray Evaluate the APL sigmoid model at temperature(s) *t*. :param t: Temperature(s) in Kelvin. :param apl0: Baseline APL (gel phase). :param c_p_g: Linear temperature coefficient. :param dAPL: APL jump across the transition. :param k: Steepness of the sigmoid. :param Tm: Melting temperature in Kelvin. :returns: Predicted APL value(s). .. py:function:: apl_residual(coeffs: jax.numpy.ndarray, data: tuple[jax.numpy.ndarray, jax.numpy.ndarray]) -> jax.numpy.ndarray Residual function for least-squares sigmoid fitting. Follows the ``residual_fun(params, *args)`` convention expected by :class:`jaxopt.LevenbergMarquardt`. The data arguments are packed into a single tuple to ensure compatibility with jaxopt's implicit differentiation. :param coeffs: Parameter vector ``[apl0, c_p_g, dAPL, k, Tm]``. :param data: Tuple of ``(sim_apls, sim_temps)`` where *sim_apls* are the observed APL values and *sim_temps* the corresponding temperatures, both of shape ``(n_temps,)``. :returns: Element-wise residual ``sim_apls - predicted_apls``. .. py:function:: get_initial_guess(sim_apls: jax.numpy.ndarray, sim_temps: jax.numpy.ndarray) -> jax.numpy.ndarray Heuristic initial guess for the sigmoid parameters. :param sim_apls: Observed APL values, shape ``(n_temps,)``. :param sim_temps: Corresponding temperatures, shape ``(n_temps,)``. :returns: Parameter vector ``[apl0, c_p_g, dAPL, k, Tm]``. .. py:function:: fit_apl_sigmoid(sim_apls: jax.numpy.ndarray, sim_temps: jax.numpy.ndarray, *, implicit_diff: bool = True, maxiter: int = 5000) -> jax.numpy.ndarray Fit the sigmoid model to APL-vs-temperature data via nonlinear least squares. Uses Levenberg-Marquardt, which is more robust than Gauss-Newton for the strongly nonlinear sigmoid model. :param sim_apls: Observed (or reweighted) APL values, shape ``(n_temps,)``. :param sim_temps: Corresponding temperatures in Kelvin, shape ``(n_temps,)``. :param implicit_diff: Whether to use implicit differentiation through the solver, allowing JAX to back-propagate gradients. :param maxiter: Maximum number of solver iterations. :returns: Fitted parameter vector ``[apl0, c_p_g, dAPL, k, Tm]``. .. py:function:: compute_membrane_tm(sim_apls: jax.numpy.ndarray, sim_temps: jax.numpy.ndarray, *, implicit_diff: bool = True) -> float Compute the membrane melting temperature from APL-vs-temperature data. Convenience wrapper around :func:`fit_apl_sigmoid` that returns just Tm. :param sim_apls: Observed (or reweighted) APL values, shape ``(n_temps,)``. :param sim_temps: Temperatures in Kelvin, shape ``(n_temps,)``. :param implicit_diff: Whether to use implicit differentiation. :returns: Melting temperature in Kelvin. .. py:class:: MembraneMeltingTemp Observable that computes lipid membrane melting temperature. Given a concatenated :class:`SimulatorTrajectory` containing frames from simulations at multiple temperatures (identified via per-frame metadata), this observable: 1. Computes per-frame area-per-lipid using :class:`AreaPerLipid`. 2. Groups frames by temperature using ``trajectory.temperature``. 3. Computes the weighted expected APL at each temperature (weighted by optional DiffTRe importance-sampling weights). 4. Fits a sigmoid to APL vs. temperature and returns the melting temperature :math:`T_m`. .. attribute:: topology MDAnalysis Universe describing the system topology. .. attribute:: lipid_sel MDAnalysis selection string for lipid tail atoms (e.g. ``"name GL1 GL2"``). .. attribute:: temperatures Array of simulation temperatures in Kelvin to fit over. .. attribute:: implicit_diff Whether to use implicit differentiation through the least-squares solver. .. attribute:: temp_rtol Relative tolerance for grouping frames by temperature. Frames with temperature within this relative tolerance are considered to belong to the same temperature group. Default is 1e-3 (0.1%). .. py:attribute:: topology :type: MDAnalysis.Universe .. py:attribute:: lipid_sel :type: str .. py:attribute:: temperatures :type: jax.numpy.ndarray .. py:attribute:: implicit_diff :type: bool :value: True .. py:attribute:: temp_rtol :type: float :value: 0.001 .. py:method:: __call__(trajectory: mythos.simulators.io.SimulatorTrajectory, weights: jax.numpy.ndarray | None = None) -> float Compute the membrane melting temperature. :param trajectory: Concatenated trajectory with per-frame temperature :param weights: Optional per-frame importance-sampling weights, shape ``(N,)``. When ``None``, uniform weights are used (equivalent to an unweighted mean per temperature). :returns: Melting temperature in Kelvin.