Skip to content

Commit

Permalink
Add stride in the input
Browse files Browse the repository at this point in the history
  • Loading branch information
comecattin committed Jun 11, 2024
1 parent 84a78b3 commit ab4647c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
12 changes: 5 additions & 7 deletions src/input_parser.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module parser_module

contains

subroutine read_config(input_file, n_atoms, n_steps, dt, box_length, tolerance, max_iter)
subroutine read_config(input_file, n_atoms, n_steps, dt, box_length, stride)
!
! Routine to read the input configuration file
!
Expand All @@ -12,8 +12,8 @@ subroutine read_config(input_file, n_atoms, n_steps, dt, box_length, tolerance,
integer :: num_args
character(len=100) :: command

integer, intent(out) :: n_atoms, n_steps, max_iter
real(8), intent(out) :: dt, box_length, tolerance
integer, intent(out) :: n_atoms, n_steps, stride
real(8), intent(out) :: dt, box_length

! Check that CLI parameters is correct
num_args = command_argument_count()
Expand All @@ -36,16 +36,14 @@ subroutine read_config(input_file, n_atoms, n_steps, dt, box_length, tolerance,
read(20, *) n_steps
read(20, *) dt
read(20, *) box_length
read(20, *) tolerance
read(20, *) max_iter
read(20, *) stride
close(20)

print *, 'Number of atoms: ', n_atoms
print *, 'Number of steps: ', n_steps
print *, 'Time step: ', dt
print *, 'Box length: ', box_length
print *, 'SHAKE Tolerance: ', tolerance
print *, 'SHAKE Max iterations: ', max_iter
print *, 'Stride: ', stride

! Remove the temporary file
call system('rm parsed_config.tmp')
Expand Down
6 changes: 2 additions & 4 deletions src/input_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ def parse_config(file_name):
n_steps = config.get('n_steps', '1000')
n_atoms = config.get('n_atoms', '30')
box_length = config.get('box_length', '10.0')
tolerance = config.get('tolerance', '1e-6')
max_iter = config.get('max_iter', '100')
stride = config.get('stride', '1')

with open('parsed_config.tmp', 'w') as f:
f.write(f'{n_atoms}\n')
f.write(f'{n_steps}\n')
f.write(f'{dt}\n')
f.write(f'{box_length}\n')
f.write(f'{tolerance}\n')
f.write(f'{max_iter}\n')
f.write(f'{stride}\n')

6 changes: 3 additions & 3 deletions src/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ program md_simulation
implicit none

! Define parameters
integer :: n_atoms, n_steps, step, num_args, max_iter
real(8) :: dt, box_length, tolerance
integer :: n_atoms, n_steps, step, num_args, stride
real(8) :: dt, box_length
character(len=100) :: input_file, output_file, output_file_energies, command
logical :: file_exists

Expand All @@ -19,7 +19,7 @@ program md_simulation
! Kinetic, potential and total energies
real(8) :: ke, pe, te

call read_config(input_file, n_atoms, n_steps, dt, box_length, tolerance, max_iter)
call read_config(input_file, n_atoms, n_steps, dt, box_length, stride)

! Allocate the arrays
allocate(positions(n_atoms, 3))
Expand Down

0 comments on commit ab4647c

Please sign in to comment.