@@ -48,18 +48,17 @@ pub struct BATripletInfo{
4848
4949
5050/// Manages a list of 'neighbors', where one neighbor is the center of a pair of atoms
51- /// (first and second atom), and the other neighbot is a simple atom (third atom).
51+ /// (first and second atom), and the other neighbor is a simple atom (third atom).
5252/// Both the length of the bond and the distance between neighbors are subjected to a spherical cutoff.
5353/// This pre-calculator can compute and cache this list within a given system
5454/// (with two distance vectors per entry: one within the bond and one between neighbors).
5555/// Then, it can re-enumerate those neighbors, either for a full system, or with restrictions on the atoms or their species.
5656///
57- /// Users can request either a "full" neighbor list (including an entry for both
58- /// `i - j` bonds and `j - i` bonds) or save memory/computational by only
59- /// working with "half" neighbor list (only including one entry for each `i - j`
60- /// bond)
57+ /// This saves memory/computational power by only working with "half" neighbor list
58+ /// This is done by only including one entry for each `i - j` bond, not both `i - j` and `j - i`.
59+ /// The order of i and j is that the atom with the smallest Z (or species ID in general) comes first.
6160///
62- /// The two first atoms may not be the same atom, but the third atom may be one of them.
61+ /// The two first atoms must not be the same atom, but the third atom may be one of them.
6362/// (When periodic boundaries arise, the two first atoms may be images of each other.)
6463#[ derive( Debug , Clone ) ]
6564#[ derive( serde:: Deserialize , serde:: Serialize , schemars:: JsonSchema ) ]
@@ -72,6 +71,7 @@ pub struct BATripletNeighborList {
7271 pub cutoffs : [ f64 ; 2 ] , // bond_, third_cutoff
7372}
7473
74+ /// the internal function doing the triplet computing itself
7575fn list_raw_triplets ( system : & mut dyn SystemBase , bond_cutoff : f64 , third_cutoff : f64 ) -> Result < Vec < BATripletInfo > , Error > {
7676 system. compute_neighbors ( bond_cutoff) ?;
7777 let bonds = system. pairs ( ) ?. to_owned ( ) ;
@@ -206,53 +206,18 @@ impl BATripletNeighborList {
206206 }
207207
208208 /// validate that the cutoffs make sense
209- pub ( crate ) fn validate_cutoffs ( & self ) { // TODO: un-pub
209+ pub fn validate_cutoffs ( & self ) {
210210 let ( bond_cutoff, third_cutoff) = ( self . bond_cutoff ( ) , self . third_cutoff ( ) ) ;
211211 assert ! ( bond_cutoff > 0.0 && bond_cutoff. is_finite( ) ) ;
212212 assert ! ( third_cutoff >= bond_cutoff && third_cutoff. is_finite( ) ) ;
213213 }
214214
215+ /// internal function that deletages computing the triplets, but deals with storing them for a given system.
215216 fn do_compute_for_system ( & self , system : & mut System ) -> Result < ( ) , Error > {
216217 // let triplets_raw = TripletNeighborsList::for_system(&**system, self.bond_cutoff(), self.third_cutoff())?;
217218 // let triplets = triplets_raw.triplets();
218219 let triplets = list_raw_triplets ( & mut * * system, self . cutoffs [ 0 ] , self . cutoffs [ 1 ] ) ?;
219220
220- //let species = system.species()?;
221-
222- // let triplets = triplets.into_iter().map(|tr|{
223- // if species[tr.atom_i] <= species[tr.atom_j] {
224- // tr
225- // } else {
226- // BATripletInfo{
227- // atom_i: tr.atom_j,
228- // atom_j: tr.atom_i,
229- // atom_k: tr.atom_k,
230- // bond_i: tr.bond_i,
231- // triplet_i: tr.triplet_i,
232- // is_self_contrib: tr.is_self_contrib,
233- // bond_vector: tr.bond_vector.map(|v|-v),
234- // third_vector: tr.third_vector,
235- // }
236- // // BATriplet{
237- // // bond_i: tr.bond_i,
238- // // bond: Pair {
239- // // first: tr.bond.second,
240- // // second: tr.bond.first,
241- // // distance: tr.bond.distance,
242- // // vector: -tr.bond.vector,
243- // // cell_shift_indices: {let c = &tr.bond.cell_shift_indices; [-c[0],-c[1],-c[2]]},
244- // // },
245- // // third: tr.third, third_vector: tr.third_vector,
246- // // is_self_contribution: tr.is_self_contribution,
247- // // distance: tr.distance,
248- // // cell_shift_indices: {
249- // // let (c1,c2) = (&tr.cell_shift_indices,&tr.bond.cell_shift_indices);
250- // // [c1[0]-c2[0],c1[1]-c2[1],c1[2]-c2[2]]
251- // // },
252- // // }
253- // }
254- // }).collect::<Vec<_>>();
255-
256221 let components = [ Labels :: new (
257222 [ "vector_pair_component" ] ,
258223 & [ [ 0x00_i32 ] , [ 0x01 ] , [ 0x02 ] , [ 0x10 ] , [ 0x11 ] , [ 0x12 ] ] ,
@@ -332,7 +297,10 @@ impl BATripletNeighborList {
332297 Ok ( ( ) )
333298 }
334299
300+ /// check that the precalculator has computed its values for a given system,
301+ /// and if not, compute them.
335302 pub fn ensure_computed_for_system ( & self , system : & mut System ) -> Result < ( ) , Error > {
303+ self . validate_cutoffs ( ) ;
336304 ' cached_path: {
337305 let cutoffs2: & [ f64 ; 2 ] = match system. data ( Self :: CACHE_NAME_ATTR . into ( ) ) {
338306 Some ( cutoff) => cutoff. downcast_ref ( )
@@ -349,6 +317,8 @@ impl BATripletNeighborList {
349317 return self . do_compute_for_system ( system) ;
350318 }
351319
320+ /// for a given system, get a copy of all the bond-atom triplets.
321+ /// optionally include the vectors tied to these triplets
352322 pub fn get_for_system ( & self , system : & System , with_vectors : bool ) -> Result < Vec < BATripletInfo > , Error > {
353323 let block: & TensorBlock = system. data ( & Self :: CACHE_NAME1 )
354324 . ok_or_else ( ||Error :: Internal ( "triplets not yet computed" . into ( ) ) ) ?
@@ -375,6 +345,9 @@ impl BATripletNeighborList {
375345 Ok ( res)
376346 }
377347
348+ /// for a given system, get a copy of the bond-atom triplets of given set of atomic species.
349+ /// optionally include the vectors tied to these triplets
350+ /// note: inverting s1 and s2 does not change the result, and the returned triplets may have these species swapped
378351 pub fn get_per_system_per_species ( & self , system : & System , s1 : i32 , s2 : i32 , s3 : i32 , with_vectors : bool ) -> Result < Vec < BATripletInfo > , Error > {
379352 let block: & TensorBlock = system. data ( & Self :: CACHE_NAME1 )
380353 . ok_or_else ( ||Error :: Internal ( "triplets not yet computed" . into ( ) ) ) ?
@@ -414,6 +387,9 @@ impl BATripletNeighborList {
414387 Ok ( res)
415388 }
416389
390+ /// for a given system, get a copy of the bond-atom triplets of given set of atomic species.
391+ /// optionally include the vectors tied to these triplets
392+ /// note: the triplets may be for (c2,c1) rather than (c1,c2)
417393 pub fn get_per_system_per_center ( & self , system : & System , c1 : usize , c2 : usize , with_vectors : bool ) -> Result < Vec < BATripletInfo > , Error > {
418394 {
419395 let sz = system. size ( ) ?;
0 commit comments