BraWl
Loading...
Searching...
No Matches
write_xyz Module Reference

Functions/Subroutines

subroutine xyz_writer (filename, configuration, setup, trajectory)
 Subroutine to write xyz file

 

Function/Subroutine Documentation

◆ xyz_writer()

subroutine write_xyz::xyz_writer ( character(len=*), intent(in) filename,
integer(array_int), dimension(:,:,:,:), intent(in) configuration,
type(run_params), intent(in) setup,
logical, optional trajectory )

Subroutine to write xyz file

This is routine writes an xyz file of the current configuration, in the extended xyz format, (incl. lattice, element type and coordinates) with option to append configurations in a single trajectory file.

Author
C. D. Woodgate
L. B. Partay
Date
2024
Parameters
filenameName of file to be created
configurationCurrent atomic configuration
setupDerived type containing simulation parameters
trajectoryLogical type, if true, configuration will be appended to the end of the file
Returns
None

Definition at line 40 of file write_xyz.f90.

41 ! Simulation setup information
42 type(run_params), intent(in) :: setup
43
44 ! Data to write to file
45 !integer(array_int), dimension(:,:,:,:), allocatable, intent(in) :: configuration
46 integer(array_int), dimension(:,:,:,:), intent(in) :: configuration
47
48 ! Option to open existing xyz file and append new configuration to the end
49 logical, optional :: trajectory
50
51 ! Sizes of grid
52 integer, dimension(4) :: grid_sizes
53
54 ! Filename to which to write
55 character(len=*), intent(in) :: filename
56
57 integer :: n_particles, i, j, k, l
58 logical :: exist
59 real(real64), dimension(3) :: pos
60
61 n_particles = total_particle_count(setup, configuration)
62
63 grid_sizes = shape(configuration)
64
65 ! Check if we want to open new xyz, overwrite existing xyz or append existing xyz file
66 if (present(trajectory)) then
67
68 if (trajectory) then
69 inquire(file=filename, exist=exist)
70 if (exist) then
71 open(7, file=filename, status="old", position="append", action="write")
72 else
73 open(7, file=filename, status="new", action="write")
74 end if
75 end if
76
77 else ! open xyz (if exists, will ovrewrite)
78
79 open(unit=7, file=filename)
80
81 endif
82
83 write(7, *) n_particles
84
85 write(7,*) 'Lattice="',setup%lattice_parameter*setup%n_1, 0.0, 0.0 , &
86 & 0.0, setup%lattice_parameter*setup%n_2, 0.0 , &
87 & 0.0, 0.0, setup%lattice_parameter*setup%n_3, '"'
88
89! if (present(trajectory)) then
90! if (trajectory) then
91! write(7,*) 'Lattice="',setup%lattice_parameter*setup%n_1, 0.0, 0.0 , &
92! & 0.0, setup%lattice_parameter*setup%n_2, 0.0 , &
93! & 0.0, 0.0, setup%lattice_parameter*setup%n_3, '"'
94! end if
95! else
96! write(7,*) ''
97! end if
98
99 do i=1, grid_sizes(1)
100 do j=1, grid_sizes(2)
101 do k=1, grid_sizes(3)
102 do l=1, grid_sizes(4)
103 if (configuration(i,j,k,l) .eq. 0) cycle
104 pos = real(j-1)*setup%lattice_vectors(1,:) + &
105 real(k-1)*setup%lattice_vectors(2,:) + &
106 real(l-1)*setup%lattice_vectors(3,:) + &
107 real(i)*setup%basis_vectors
108 pos = pos*setup%lattice_parameter
109 write(7,*) setup%species_names(configuration(i,j,k,l)), pos(1),pos(2),pos(3)
110 end do
111 end do
112 end do
113 end do
114
115 close(unit=7)
116
Here is the call graph for this function:
Here is the caller graph for this function: