pub(crate) fn lammps_diff_fn(&self, coords: &Coords, meta: M) -> FailResult<Box<dyn DiffFn<M>>>
    {
        // a DiffFn 'lambda' whose type will be erased
        struct MyDiffFn<Mm: Clone>(::rsp2_lammps_wrap::Lammps<Box<dyn LammpsPotential<Meta=Mm>>>);
        impl<Mm: Clone> DiffFn<Mm> for MyDiffFn<Mm> {
            fn compute(&mut self, coords: &Coords, meta: Mm) -> FailResult<(f64, Vec<V3>)> {
                let lmp = &mut self.0;

                lmp.set_structure(coords.clone(), meta)?;
                let value = lmp.compute_value()?;
                let grad = lmp.compute_grad()?;
                Ok((value, grad))
            }
        }

        // (panic on lock already acquired; blocking could easily deadlock)
        let lock = if self.allow_blocking {
            INSTANCE_LOCK.lock()
                .expect("LAMMPS lock was poisoned!")
        } else {
            INSTANCE_LOCK.try_lock()
                .expect("Tried to construct multiple Lammps instances in parallel")
        };

        let lammps_pot = Box::new(self.potential.clone()) as Box<dyn LammpsPotential<Meta=P::Meta>>;
        let lmp = self.inner.build(lock, lammps_pot, coords.clone(), meta)?;
        Ok(Box::new(MyDiffFn::<M>(lmp)) as Box<_>)
    }
/// Initialize Lammps to make a DiffFn.
///
/// This keeps the Lammps instance between calls to save time.
///
/// Some data may be pre-allocated or precomputed based on the input structure,
/// so the resulting DiffFn may not support arbitrary structures as input.
Initialize Lammps to make a DiffFn.
This keeps the Lammps instance between calls to save time.

Some data may be pre-allocated or precomputed based on the input structure,
so the resulting DiffFn may not support arbitrary structures as input.
Initialize Lammps to make a DiffFn . This keeps the Lammps instance between calls to save time . Some data may be pre - allocated or precomputed based on the input structure so the resulting DiffFn may not support arbitrary structures as input .
pub(crate) fn lammps_diff_fn(&self, coords: &Coords, meta: M) -> FailResult<Box<dyn DiffFn<M>>>
    {
        // a DiffFn 'lambda' whose type will be erased
        struct MyDiffFn<Mm: Clone>(::rsp2_lammps_wrap::Lammps<Box<dyn LammpsPotential<Meta=Mm>>>);
        impl<Mm: Clone> DiffFn<Mm> for MyDiffFn<Mm> {
            fn compute(&mut self, coords: &Coords, meta: Mm) -> FailResult<(f64, Vec<V3>)> {
                let lmp = &mut self.0;
                lmp.set_structure(coords.clone(), meta)?;
                let value = lmp.compute_value()?;
                let grad = lmp.compute_grad()?;
                Ok((value, grad))
            }
        }
        // (panic on lock already acquired; blocking could easily deadlock)
        let lock = if self.allow_blocking {
            INSTANCE_LOCK.lock()
                .expect("LAMMPS lock was poisoned!")
        } else {
            INSTANCE_LOCK.try_lock()
                .expect("Tried to construct multiple Lammps instances in parallel")
        };
        let lammps_pot = Box::new(self.potential.clone()) as Box<dyn LammpsPotential<Meta=P::Meta>>;
        let lmp = self.inner.build(lock, lammps_pot, coords.clone(), meta)?;
        Ok(Box::new(MyDiffFn::<M>(lmp)) as Box<_>)
    }
pub ( crate ) fn lammps_diff_fn ( & self , coords : & Coords , meta : M ) -> FailResult < Box < dyn DiffFn < M > > > { // a DiffFn 'lambda' whose type will be erased struct MyDiffFn < Mm : Clone > ( :: rsp2_lammps_wrap :: Lammps < Box < dyn LammpsPotential < Meta = Mm > > > ) ; impl < Mm : Clone > DiffFn < Mm > for MyDiffFn < Mm > { fn compute ( & mut self , coords : & Coords , meta : Mm ) -> FailResult < ( f64 , Vec < V3 > ) > { let lmp = & mut self . 0 ; lmp . set_structure ( coords . clone ( ) , meta ) ? ; let value = lmp . compute_value ( ) ? ; let grad = lmp . compute_grad ( ) ? ; Ok ( ( value , grad ) ) } } // (panic on lock already acquired; blocking could easily deadlock) let lock = if self . allow_blocking { INSTANCE_LOCK . lock ( ) . expect ( " " ) } else { INSTANCE_LOCK . try_lock ( ) . expect ( " " ) } ; let lammps_pot = Box :: new ( self . potential . clone ( ) ) as Box < dyn LammpsPotential < Meta = P :: Meta > > ; let lmp = self . inner . build ( lock , lammps_pot , coords . clone ( ) , meta ) ? ; Ok ( Box :: new ( MyDiffFn :: < M > ( lmp ) ) as Box < _ > ) }
Initialize Lammps to make a DiffFn.
Initialize Lammps to make a DiffFn .
&self
coords
&Coords
meta
M
&self
coords
&Coords
meta
M