fn initialize_cg_diff_fn(&self, init_coords: &Coords, meta: Meta) -> FailResult<Box<DynCgDiffFn<'static>>>
    where Meta: Clone + 'static
    {
        struct Adapter<Meta2> {
            diff_fn: Box<dyn DiffFn<Meta2>>,
            coords: Coords,
            meta: Meta2,
        }

        impl<Meta2: Clone> rsp2_minimize::cg::DiffFn for Adapter<Meta2> {
            type Error = failure::Error;

            fn compute(&mut self, pos: &[f64]) -> FailResult<(f64, Vec<f64>)> {
                let Adapter { ref mut diff_fn, ref mut coords, ref meta } = *self;

                coords.set_carts(pos.nest().to_vec());

                let (value, grad) = diff_fn.compute(&coords, meta.clone())?;
                Ok((value, grad.unvee().flat().to_vec()))
            }

            fn check(&mut self, pos: &[f64]) -> FailResult<()> {
                let Adapter { ref mut diff_fn, ref mut coords, ref meta } = *self;

                coords.set_carts(pos.nest().to_vec());

                diff_fn.check(&coords, meta.clone())
            }
        }

        let diff_fn = self.initialize_diff_fn(init_coords, meta.clone())?;
        let coords = init_coords.clone();
        Ok(Box::new(Adapter { diff_fn, coords, meta }) as Box<_>)
    }
/// Convenience method to get a function suitable for `rsp2_minimize`.
///
/// The structure given to this is used to supply the lattice and metadata.
/// Also, some other data may be precomputed from it.
Convenience method to get a function suitable for `rsp2_minimize`.
The structure given to this is used to supply the lattice and metadata.
Also, some other data may be precomputed from it.
Convenience method to get a function suitable for ` rsp2_minimize ` . The structure given to this is used to supply the lattice and metadata . Also some other data may be precomputed from it .
fn initialize_cg_diff_fn(&self, init_coords: &Coords, meta: Meta) -> FailResult<Box<DynCgDiffFn<'static>>>
    where Meta: Clone + 'static
    {
        struct Adapter<Meta2> {
            diff_fn: Box<dyn DiffFn<Meta2>>,
            coords: Coords,
            meta: Meta2,
        }
        impl<Meta2: Clone> rsp2_minimize::cg::DiffFn for Adapter<Meta2> {
            type Error = failure::Error;
            fn compute(&mut self, pos: &[f64]) -> FailResult<(f64, Vec<f64>)> {
                let Adapter { ref mut diff_fn, ref mut coords, ref meta } = *self;
                coords.set_carts(pos.nest().to_vec());
                let (value, grad) = diff_fn.compute(&coords, meta.clone())?;
                Ok((value, grad.unvee().flat().to_vec()))
            }
            fn check(&mut self, pos: &[f64]) -> FailResult<()> {
                let Adapter { ref mut diff_fn, ref mut coords, ref meta } = *self;
                coords.set_carts(pos.nest().to_vec());
                diff_fn.check(&coords, meta.clone())
            }
        }
        let diff_fn = self.initialize_diff_fn(init_coords, meta.clone())?;
        let coords = init_coords.clone();
        Ok(Box::new(Adapter { diff_fn, coords, meta }) as Box<_>)
    }
fn initialize_cg_diff_fn ( & self , init_coords : & Coords , meta : Meta ) -> FailResult < Box < DynCgDiffFn < ' static > > > where Meta : Clone + ' static { struct Adapter < Meta2 > { diff_fn : Box < dyn DiffFn < Meta2 > > , coords : Coords , meta : Meta2 , } impl < Meta2 : Clone > rsp2_minimize :: cg :: DiffFn for Adapter < Meta2 > { type Error = failure :: Error ; fn compute ( & mut self , pos : & [ f64 ] ) -> FailResult < ( f64 , Vec < f64 > ) > { let Adapter { ref mut diff_fn , ref mut coords , ref meta } = * self ; coords . set_carts ( pos . nest ( ) . to_vec ( ) ) ; let ( value , grad ) = diff_fn . compute ( & coords , meta . clone ( ) ) ? ; Ok ( ( value , grad . unvee ( ) . flat ( ) . to_vec ( ) ) ) } fn check ( & mut self , pos : & [ f64 ] ) -> FailResult < ( ) > { let Adapter { ref mut diff_fn , ref mut coords , ref meta } = * self ; coords . set_carts ( pos . nest ( ) . to_vec ( ) ) ; diff_fn . check ( & coords , meta . clone ( ) ) } } let diff_fn = self . initialize_diff_fn ( init_coords , meta . clone ( ) ) ? ; let coords = init_coords . clone ( ) ; Ok ( Box :: new ( Adapter { diff_fn , coords , meta } ) as Box < _ > ) }
Convenience method to get a function suitable for `rsp2_minimize`.
Convenience method to get a function suitable for ` rsp2_minimize ` .
&self
init_coords
&Coords
meta
Meta
&self
init_coords
&Coords
meta
Meta