@@ -40,13 +40,12 @@ impl Particle {
4040 }
4141
4242 /// Calculates energy of particle-surface interaction.
43+ /// Only supports 1D simulations.
4344 pub fn energy_surface ( & self ) -> f64 {
44- self . binding * ( 1.0 +
45- ( 2.0 * PI * ( self . position [ 0 ] / self . wells_distance + self . sin_shift ) ) . sin ( ) +
46- ( 2.0 * PI * ( self . position [ 1 ] / self . wells_distance + self . cos_shift ) ) . cos ( )
47- )
45+ self . binding * num_traits:: sign:: signum ( ( 2.0 * PI * ( self . position [ 0 ] / self . wells_distance + self . sin_shift ) ) . sin ( ) )
4846 }
4947
48+
5049 /// Proposes a translation move for a particle in 2D space.
5150 ///
5251 /// ## Details
@@ -104,72 +103,10 @@ mod tests {
104103 fn test_particle_surface_energy ( ) {
105104
106105 let system = parse_input ( INPUT_FILE ) . expect ( "Could not find input file." ) ;
107- let expected = [ -1.0 , 3.0 , - 0.0 , 0.25 , 0.08244 ] ;
106+ let expected = [ -1.0 , 3.0 , 0.0 , 0.5 , - 0.2 ] ;
108107 for ( i, particle) in system. particles . iter ( ) . enumerate ( ) {
109108 assert ! ( ( particle. energy_surface( ) - expected[ i] ) . abs( ) < 0.0001 ) ;
110109 }
111110 }
112-
113- #[ test]
114- fn test_particle_propose_move_1d ( ) {
115-
116- let mut rng = rand:: thread_rng ( ) ;
117- let n_moves = 10_000usize ;
118-
119- let displacements = [ 0.1 , 0.5 , 1.0 ] ;
120-
121- for i in 0 ..3 {
122- let mut particle = Particle :: new ( [ 0.0 , 0.0 ] , 0.0 , displacements[ i] , 0.0 , 1.0 , 0.0 , 0.0 ) ;
123-
124- let orig_pos_x = particle. position [ 0 ] ;
125-
126- for _ in 0 ..n_moves {
127- let old_pos_x = particle. position [ 0 ] ;
128-
129- particle. propose_move_1d ( & mut rng) ;
130-
131- assert ! ( ( particle. position[ 0 ] - old_pos_x) . abs( ) < particle. max_disp) ;
132- assert_eq ! ( particle. position[ 1 ] , 0.0 ) ;
133- }
134-
135- //println!("Total difference: {}", particle.position[0] - orig_pos_x);
136- // this may in very rare cases fail
137- assert ! ( ( particle. position[ 0 ] - orig_pos_x) . abs( ) < particle. max_disp * 200.0 ) ;
138- }
139- }
140-
141- #[ test]
142- fn test_particle_propose_move_2d ( ) {
143-
144- let mut rng = rand:: thread_rng ( ) ;
145- let n_moves = 10_000usize ;
146-
147- let displacements = [ 0.1 , 0.5 , 1.0 ] ;
148-
149- for i in 0 ..3 {
150- let mut particle = Particle { position : [ 0.0 , 0.0 ] , binding : 0.0 , max_disp : displacements[ i] , size : 0.0 , wells_distance : 1.0 , sin_shift : 0.0 , cos_shift : 0.0 } ;
151-
152- let orig_pos_x = particle. position [ 0 ] ;
153- let orig_pos_y = particle. position [ 1 ] ;
154-
155- for _ in 0 ..n_moves {
156- let old_pos_x = particle. position [ 0 ] ;
157- let old_pos_y = particle. position [ 1 ] ;
158-
159- particle. propose_move_2d ( & mut rng) ;
160-
161- let dx = particle. position [ 0 ] - old_pos_x;
162- let dy = particle. position [ 1 ] - old_pos_y;
163-
164- assert ! ( ( dx * dx + dy * dy) . sqrt( ) . abs( ) < particle. max_disp) ;
165- }
166-
167- //println!("Total difference: {} {}", particle.position[0] - orig_pos_x, particle.position[1] - orig_pos_y);
168- // these two may in very rare cases fail
169- assert ! ( ( particle. position[ 0 ] - orig_pos_x) . abs( ) < particle. max_disp * 200.0 ) ;
170- assert ! ( ( particle. position[ 1 ] - orig_pos_y) . abs( ) < particle. max_disp * 200.0 ) ;
171-
172- }
173- }
174111
175112}
0 commit comments