fn initialize_diff_fn(&self, coords: &Coords, meta: CommonMeta) -> FailResult<Box<dyn DiffFn<CommonMeta>>>
    {
        let elements: meta::SiteElements = meta.pick();

        let mut dftb_builder = self.inner.clone();
        let dftb = {
            dftb_builder
                .initial_coords(coords)
                .elements(&elements)
                .build()?
        };

        // a DiffFn 'lambda' whose type will be erased
        struct MyDiffFn(wrapper::DftbPlus);
        impl DiffFn<CommonMeta> for MyDiffFn {
            fn compute(&mut self, coords: &Coords, meta: CommonMeta) -> FailResult<(f64, Vec<V3>)> {
                let dftb = &mut self.0;

                let elements: meta::SiteElements = meta.pick();
                if &elements[..] != dftb.elements() {
                    bail!{ "\
                        Detected change in site elements! This is not supported by \
                        the dftb+ potential.\
                    "};
                }

                dftb.set_coords(coords)?;

                let value = dftb.compute_value()?;
                let grad = dftb.compute_grad()?;
                Ok((value, grad))
            }
        }

        Ok(Box::new(MyDiffFn(dftb)) as Box<_>)
    }
/// Initialize DFTB+ to make a DiffFn.
///
/// This keeps the DFTB+ 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 DFTB+ to make a DiffFn.
This keeps the DFTB+ 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 DFTB + to make a DiffFn . This keeps the DFTB + 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 .
fn initialize_diff_fn(&self, coords: &Coords, meta: CommonMeta) -> FailResult<Box<dyn DiffFn<CommonMeta>>>
    {
        let elements: meta::SiteElements = meta.pick();
        let mut dftb_builder = self.inner.clone();
        let dftb = {
            dftb_builder
                .initial_coords(coords)
                .elements(&elements)
                .build()?
        };
        // a DiffFn 'lambda' whose type will be erased
        struct MyDiffFn(wrapper::DftbPlus);
        impl DiffFn<CommonMeta> for MyDiffFn {
            fn compute(&mut self, coords: &Coords, meta: CommonMeta) -> FailResult<(f64, Vec<V3>)> {
                let dftb = &mut self.0;
                let elements: meta::SiteElements = meta.pick();
                if &elements[..] != dftb.elements() {
                    bail!{ "\
                        Detected change in site elements! This is not supported by \
                        the dftb+ potential.\
                    "};
                }
                dftb.set_coords(coords)?;
                let value = dftb.compute_value()?;
                let grad = dftb.compute_grad()?;
                Ok((value, grad))
            }
        }
        Ok(Box::new(MyDiffFn(dftb)) as Box<_>)
    }
fn initialize_diff_fn ( & self , coords : & Coords , meta : CommonMeta ) -> FailResult < Box < dyn DiffFn < CommonMeta > > > { let elements : meta :: SiteElements = meta . pick ( ) ; let mut dftb_builder = self . inner . clone ( ) ; let dftb = { dftb_builder . initial_coords ( coords ) . elements ( & elements ) . build ( ) ? } ; // a DiffFn 'lambda' whose type will be erased struct MyDiffFn ( wrapper :: DftbPlus ) ; impl DiffFn < CommonMeta > for MyDiffFn { fn compute ( & mut self , coords : & Coords , meta : CommonMeta ) -> FailResult < ( f64 , Vec < V3 > ) > { let dftb = & mut self . 0 ; let elements : meta :: SiteElements = meta . pick ( ) ; if & elements [ .. ] != dftb . elements ( ) { bail ! { " \
 \
 \
 " } ; } dftb . set_coords ( coords ) ? ; let value = dftb . compute_value ( ) ? ; let grad = dftb . compute_grad ( ) ? ; Ok ( ( value , grad ) ) } } Ok ( Box :: new ( MyDiffFn ( dftb ) ) as Box < _ > ) }
Initialize DFTB+ to make a DiffFn.
Initialize DFTB + to make a DiffFn .
&self
coords
&Coords
meta
CommonMeta
&self
coords
&Coords
meta
CommonMeta