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.
41
42 type(run_params), intent(in) :: setup
43
44
45
46 integer(array_int), dimension(:,:,:,:), intent(in) :: configuration
47
48
49 logical, optional :: trajectory
50
51
52 integer, dimension(4) :: grid_sizes
53
54
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
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
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
90
91
92
93
94
95
96
97
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