forked from NANIMproj/NANIM_PNNL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDWN_File.cpp
More file actions
2407 lines (2084 loc) · 76.5 KB
/
Copy pathDWN_File.cpp
File metadata and controls
2407 lines (2084 loc) · 76.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include "DWN_File.h"
//Files to be used with other programs---
void Write_GULP_File(const atom_collection& atoms, const char* Wfile_name,
const char* Dfile_name, bool include_hydro, bool overwrite_mass,
bool cat_coreshell, bool ani_coreshell)
//GULP structural optimization file.
{
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
out_file.precision(7);
//File header/keywords---
out_file << "conp opti" << endl;
//Periodicity vectors---
double cell_temps[3];
atoms.Get_Box_Vectors(cell_temps);
Multiply_XYZ(cell_temps, 10.0);
//Convert nm to Angstroms.
GULP_Ortho_Vector_Output(out_file, atoms.Get_Periodicity(), cell_temps);
//Output cell vectors.
//List of atoms---
out_file << endl << "Cartesian region 1";
if (!cat_coreshell && !ani_coreshell)
{
atoms.Store_Atoms_Location(out_file, include_hydro);
}
else
{
atoms.Store_Atoms_Location_With_CoreShell(out_file, include_hydro,
cat_coreshell, ani_coreshell);
}
//Inclusion of simulation potential library---
if (SIMULATION_POT_LIB)
{
out_file << endl << endl << "library NANIM.lib";
}
//Output files request for dump files and .frc files---
out_file << endl << endl << "dump " << Dfile_name;
char force_name[MAX_FILE_NAME_LENGTH];
strcpy(force_name, Dfile_name);
Change_File_Type(force_name, "frc");
out_file << endl << endl << "output frc " << force_name;
out_file.close();
}
}
void Write_GULP_Melt_File(const atom_collection& atoms, const char* Wfile_name,
const char* Rfile_name, bool include_hydro, bool overwrite_mass,
bool cat_coreshell, bool ani_coreshell, const MD_param& mpam)
{
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
out_file.precision(7);
//File header/keywords---
out_file << "md ";
if (mpam.nvt_run) out_file << "conv ";
if (mpam.npt_run) out_file << "conp ";
if (mpam.molecule_commands) out_file << "molecule fix_molecule nointernalke" << endl;
//Simulation title---
out_file << "title" << endl << "NANIM Simulation" << endl << "end";
//Periodicity vectors---
double cell_temps[3];
atoms.Get_Box_Vectors(cell_temps);
Multiply_XYZ(cell_temps, 10.0);
//Convert nm to Angstroms.
GULP_Ortho_Vector_Output(out_file, atoms.Get_Periodicity(), cell_temps);
//Output cell vectors.
//Atomic relative mass for simulation, if requested---
if (overwrite_mass)
{
out_file << endl << "element" << endl;
atoms.Store_Atom_Types_With_Masses(out_file, include_hydro);
out_file << "end";
}
//List of atoms---
out_file << endl << "Cartesian region 1";
if (!cat_coreshell && !ani_coreshell)
{
atoms.Store_Atoms_Location(out_file, include_hydro);
}
else
{
atoms.Store_Atoms_Location_With_CoreShell(out_file, include_hydro,
cat_coreshell, ani_coreshell);
}
//Molecular dynamics parameters---
out_file << endl << endl << "integrator leapfrog verlet" << endl << "ensemble ";
//Integrator for MD equations.
if (mpam.nvt_run) out_file << "nvt " << mpam.thermo_coeff << endl;
if (mpam.npt_run) out_file << "npt " << mpam.thermo_coeff << " " << mpam.baro_coeff << endl;
//NVT vs. NPT along with pressure/temperature control coefficients.
//Temperature information, which may include details on how to change temperature
//over time (e.g. so one simulation file can do an annealing test)---
out_file << "temperature " << mpam.initial_temp;
double temp_change = mpam.final_temp - mpam.initial_temp;
if (!Check_FP_Equality(temp_change, 0.0))
//If final temperature matches initial temperature, this can only be the case when
//no temperature change is desired. GULP simulation temperature information is for
//an initial constant-temperature simulation timeframe followed by changing temperature.
{
double step_count_over_initial_temp = mpam.initial_temp_time/(mpam.time_step/1000.0);
//Number of time steps over the initial constant-temperature phase of the simulation.
double step_count_over_temp_change = mpam.change_temp_time/(mpam.time_step/1000.0);
//Number of time steps over the dynamic temperature phase of the simulation.
double temp_change_per_step = temp_change/step_count_over_temp_change;
//Value of the change in temperature in timestep (typically ~0.03 K/fs) for the
//dynamic temperature phase of the simulation.
out_file << " " << temp_change_per_step << " "
<< int(step_count_over_temp_change + FP_ERROR_FIX) << " "
<< int(step_count_over_initial_temp + FP_ERROR_FIX);
}
//Times for equilibrium, production, timesteps, and for results being shown
//on screen (sample)/in file (write)---
out_file << endl << "equil " << mpam.equi_time << " ps" << endl
<< "produ " << mpam.prod_time << " ps" << endl
<< "timestep " << mpam.time_step << " fs" << endl
<< "sample " << mpam.supdate_time << " ps" << endl
<< "write_MD " << mpam.fupdate_time << " ps" << endl;
//Simulation library inclusion---
if (SIMULATION_POT_LIB)
{
out_file << endl << endl << "library NANIM.lib";
}
//Output file requests for dump files and MD history files---
out_file << endl << endl << "dump every 1 " << Rfile_name;
char history_name[MAX_FILE_NAME_LENGTH];
strcpy(history_name, Rfile_name);
Change_File_Type(history_name, "his");
out_file << endl << endl << "output history " << history_name;
out_file.close();
}
}
void Write_PDB_File(const atom_collection& atoms, const char* Wfile_name,
bool include_hydro)
{
char line_feed = char(10);
//Correct way to terminate lines in a PDB file.
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
//Get cell vectors---
double cell_vecs[3];
atoms.Get_Box_Vectors(cell_vecs);
//Get orthorhombic box sizes.
Multiply_XYZ(cell_vecs, 10.0);
//Convert from nm to Angstroms.
//Header of PDB file---
char system_name[MAX_FILE_NAME_LENGTH];
Copy_With_No_Extension(system_name, Wfile_name);
Remove_Root(system_name);
//Use the file name without the root or extension as a title name for the PDB file.
out_file << "HEADER DWN FILE GENERATOR PDB FILE";
out_file << line_feed << "TITLE " << system_name;
out_file << line_feed << "REMARK 1 ENJOY THIS PDB FILE";
//Crystal system information---
out_file << line_feed << "CRYST1";
int dimension = 0;
int period = atoms.Get_Periodicity();
if (period == 0)
//O-D PDB files have a special case for what is placed on the "CRYST" line.
{
Show_Statement("Note: You have a 0D-PDB File with according crystal format!");
}
for (dimension; dimension < period; ++dimension)
{
Right_Justify(out_file, cell_vecs[dimension], 3, 9);
}
for (dimension; dimension < 3; ++dimension)
{
if (period == 0)
{
Right_Justify(out_file, 1.0, 3, 9);
//Default = 1.000 for 0-D case, according to PDB-file format.
}
else
{
Right_Justify(out_file, 0.0, 3, 9);
}
}
//out_file.precision(2);
out_file << " 90.00 90.00 90.00 P 1 1";
//Periodicity vector angles and crystal space group.
//Default: Orthorhombic with no inherent symmetry.
//Model line---
out_file << line_feed << "MODEL 1";
//Atom listing---
double coors[3];
char atom_name[MAX_ANAME_SIZE];
int string_length;
int atom_count = 0;
int group_tag_index;
for (int a = 0; a < atoms.Size(); ++a)
{
if (!atoms[a].Is_Invisible(include_hydro))
//Don't include invisible atoms.
{
out_file << line_feed << "HETATM";
//Leading atom keyword.
//Atom index/serial number---
++atom_count;
Right_Justify(out_file, atom_count, 5);
//Right-justify the atom index/serial number.
//Atom name---
out_file << ' ';
atoms[a].Get_Atom_Name(atom_name);
string_length = strlen(atom_name);
if (!Is_Text(atom_name[1]))
//Atomic symbol (i.e. without number) is to be
//right-justified within the first two columns
//of the atom name area.
{
out_file << " ";
++string_length;
}
out_file << atom_name;
//Residue name/chain ID/sequence number---
Output_Spaces(out_file, 5 - string_length);
out_file << "AAA A";
//Default residue name and chain ID.
group_tag_index = atoms.Get_Group_Tag(a);
Right_Justify(out_file, group_tag_index, 4);
out_file << " ";
//Use the group tag (i.e. molecular index) as
//a "residue" sequence number.
//Atomic location---
atoms[a].Get_Atom_Location(coors);
for (int c = 0; c < 3; ++c)
{
Right_Justify(out_file, coors[c]*10.0, 3, 8);
}
//Occupancy and temperature factor---
out_file << " 1.00 0.00 ";
//Atomic symbol---
atoms[a].Get_Atom_Name(atom_name);
if (!Is_Text(atom_name[1]))
//Right-justify atomic symbol.
{
out_file << " ";
}
Remove_Number(atom_name);
out_file << atom_name;
//Use index-less atom name as the atomic symbol.
}
}
//ENDMDL line----
out_file << line_feed << "ENDMDL";
out_file.close();
}
}
void Write_LAMMPS_File(const atom_collection& atoms, const char* Wfile_name,
bool include_hydro)
{
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
out_file.close();
}
}
void Write_XYZ_File(const atom_collection& atoms, const char* Wfile_name, bool include_hydro)
{
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
//Header---
out_file << atoms.Real_Size(include_hydro) << endl;
//Write number of atoms to be included in the XYZ file.
char system_name[50];
Copy_With_No_Extension(system_name, Wfile_name);
//Use the file name without the extension as the system name.
out_file << system_name << endl;
//System name.
//Atom listing---
double coors[3];
char temp_atom_name[MAX_ANAME_SIZE];
out_file.precision(6);
out_file << fixed;
for (int a = 0; a < atoms.Size(); ++a)
{
if (!atoms[a].Is_Invisible(include_hydro))
//Don't include invisible atoms.
{
atoms[a].Get_Atom_Name(temp_atom_name);
Remove_Number(temp_atom_name);
//No indexing of atoms in XYZ file!
atoms[a].Get_Atom_Location(coors);
Multiply_XYZ(coors, 10.0);
//Convert to Angstroms.
out_file << " " << temp_atom_name << " ";
Output_Spaces(out_file, 9 - strlen(temp_atom_name));
for (int a = 0; a < 3; ++a)
{
Left_Justify(out_file, coors[a], 6, 16);
}
}
}
out_file.close();
}
}
void Write_GSPE_File(const atom_collection& atoms, const char* Wfile_name, bool include_hydro)
{
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
//Header information---
out_file << "# HF/6-31G(d)" << endl << endl;
char system_name[50];
Copy_With_No_Extension(system_name, Wfile_name);
//Use the file name without the extension as the test name.
out_file << system_name << " SPE calculation" << endl << endl;
//Charge/multiplicity information---
out_file << int(atoms.Return_Total_Charge() * (1 + FP_ERROR_FIX));
//System net charge.
out_file << " 1" << endl;
//Spin multiplicity assumed to be one (singlet).
//Atomic listing, looks just like the XYZ listing,
//for the moment---
out_file.precision(4);
out_file << fixed;
double coors[3];
char temp_atom_name[MAX_ANAME_SIZE];
for (int a = 0; a < atoms.Size(); ++a)
{
if (!atoms[a].Is_Invisible(include_hydro))
//Don't consider invisible atoms.
{
atoms[a].Get_Atom_Name(temp_atom_name);
Remove_Number(temp_atom_name);
//No indexing of atoms!
atoms[a].Get_Atom_Location(coors);
Multiply_XYZ(coors, 10.0);
//Convert to Angstroms.
out_file << temp_atom_name << " ";
Output_Spaces(out_file, 5 - strlen(temp_atom_name));
for (int a = 0; a < 3; ++a)
{
Left_Justify(out_file, coors[a], 3, 10);
}
}
}
out_file.close();
}
}
void Write_QSTEM_File(const atom_collection& atoms, const char* Wfile_name, bool include_hydro,
bool include_DWF)
{
ofstream out_file(Wfile_name, ios::out);
char line_feed = char(10);
//Note: Do not use carriage returns with QSTEM!
if (out_file.is_open())
{
out_file.precision(7);
//Header info of particle count and distance unit---
out_file << "Number of particles = " << atoms.Real_Size(include_hydro);
//Number of atoms to be used in the QSTEM image simulation.
out_file << line_feed << "A = 1.0 Angstrom";
//Unit = Angstroms.
//QSTEM simulation box vectors---
double cell_vec[3];
atoms.Get_Box_Vectors(cell_vec);
for (int a = 0; a < 9; ++a)
//Output QSTEM cell (which has a periodicity much like a surface
//when simulating electron beam interaction).
{
out_file << line_feed << "H0(" << 1 + a/3 << "," << 1 + a%3
<< ") = ";
if ( (a % 3) == (a / 3) )
//Diagonal matrix element.
{
out_file << cell_vec[a / 3]*10.0;
}
else
{
out_file << '0';
}
out_file << " A";
//e.g. H0(1,1) = 60 A
//H0(1,2) = 0 A, etc.
}
//No velocity line and number of parameters used per atom---
out_file << line_feed << line_feed << ".NO_VELOCITY.";
//Turns off MD simulation component.
int entry_count = 3;
//Give three Cartesian coordinates per atom.
if (include_DWF)
//Also include a Debye-Waller factor with each atom.
{
entry_count = 4;
}
out_file << line_feed << line_feed << line_feed << "entry_count = "
<< entry_count << line_feed;
//Atom listing, done with atom name-based categories
//(i.e. like atoms are grouped together)---
char** atom_names;
Get_Memory(atom_names, MAX_ATOM_TYPES, MAX_ANAME_SIZE);
//List of atom names, one per atom type.
int num_atom_types;
//Number of atom names in the system (not exceeding the maximum value).
atoms.Get_Name_List(atom_names, num_atom_types, MAX_ATOM_TYPES);
const int MAX_INDEX = 100;
double** dwf_vals;
if (include_DWF)
{
Get_Memory(dwf_vals, MAX_ATOMIC_NUMBER, MAX_INDEX);
//Get the Debye-Waller factors from file.
Load_DW_Factors(dwf_vals);
}
int atomic_number;
int atom_index;
double coors[3];
bool first_find;
char temp_atom_name[MAX_ANAME_SIZE];
for (int name_index = 0; name_index < num_atom_types; ++name_index)
//Output atomic information list by list, via the atomic symbol.
//(e.g. list all the Si atoms first, then H atoms, etc.)
{
first_find = TRUEV;
for (int a = 0; a < atoms.Size(); ++a)
{
atoms[a].Get_Atom_Name(temp_atom_name);
atom_index = Get_Number(temp_atom_name);
if (Name_Check(atom_names[name_index], temp_atom_name))
//Found an atom in the category being considered.
{
if (!atoms[a].Is_Invisible(include_hydro))
//Don't consider invisible atoms.
{
if (first_find)
//Category header output.
{
out_file << int(atoms[a].Get_Atom_Rel_Mass() + FP_ERROR_FIX)
<< line_feed << temp_atom_name << line_feed;
first_find = FALSEV;
}
atoms[a].Get_Atom_Location(coors);
out_file << coors[0]/cell_vec[0] << " " << coors[1]/cell_vec[1]
<< " " << coors[2]/cell_vec[2];
//Orthorhombic box logic. QSTEM requires relative coordinates.
atomic_number = atoms[a].Get_Atom_Number();
if (include_DWF)
{
out_file << " " << dwf_vals[atomic_number][atom_index];
}
out_file << line_feed;
}
}
}
}
if (include_DWF)
{
Free_Memory(dwf_vals, MAX_ATOMIC_NUMBER);
}
Free_Memory(atom_names, MAX_ATOM_TYPES);
out_file.close();
}
}
void Write_QSC_File(const char* QSCfile_name, const char* CFGfile_name, scope_param& spam,
double col_height)
{
char line_feed = char(10);
//Note: Do not use carriage returns with QSTEM!
ofstream out_file(QSCfile_name, ios::out);
if (!out_file.is_open())
{
Show_Warning("COULD NOT OPEN QSC OUTPUT FILE!");
return;
}
out_file.setf(ios::fixed, ios::floatfield);
out_file.precision(8);
//Set precision settings.
char fold_name[40] = "C:\\QSTEM_RUN_FILES\\";
//Folder where atomic input file (.cfg) is located, at least by .qsc file's logic.
//This can be changed by loading the input file in QSTEM and resaving the .qsc file.
char test_file_name[MAX_FILE_NAME_LENGTH];
strcpy(test_file_name, CFGfile_name);
Remove_Root(test_file_name);
//Get name of the .cfg file name used by the .qsc simulation file.
char test_folder_name[MAX_FILE_NAME_LENGTH];
strcpy(test_folder_name, CFGfile_name);
Remove_Extension(test_folder_name);
Remove_Root(test_folder_name);
//Get full name of folder for storing simulation results.
//Header statement---
out_file << line_feed << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
out_file << line_feed << "% QSTEM configuration file generated by DWN File Maker!";
out_file << line_feed << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
//Microscope operating mode---
out_file << line_feed << line_feed << "mode: ";
if (spam.scope_mode == TEM_MODE)
{
out_file << "TEM";
}
else if (spam.scope_mode == CBED_MODE)
{
out_file << "CBED";
}
else
{
out_file << "STEM";
}
//"Basic" simulation parameters---
out_file << line_feed << "print level: 2";
out_file << line_feed << "save level: 0";
//Output file style for QSTEM results (default = 2 and 0).
out_file << line_feed << "filename: \"" << test_file_name << '\"';
//File location for .cfg input file.
out_file << line_feed << "resolutionX: " << spam.image_x_res;
out_file << line_feed << "resolutionY: " << spam.image_y_res;
//Point sampling of electron beam/point-to-point resolution of electron beam in simulation.
//Typically <= 0.05 A.
out_file << line_feed << "NCELLX: " << spam.cell_x;
out_file << line_feed << "NCELLY: " << spam.cell_y;
out_file << line_feed << "NCELLZ: " << spam.cell_z;
//Number of unit cells to periodically repeat when creating simulation box.
out_file << line_feed << "v0: " << spam.voltage;
//Voltage of electron beam.
out_file << line_feed << "tds: ";
//Thermal diffuse scattering (thermal movement of atoms).
if (spam.TDS_runs != 0)
{
out_file << "yes";
}
else
{
out_file << "no";
}
out_file << line_feed << "temperature: " << spam.scope_temp;
//Microscope temperature.
//Multi-slice aspects of the calculation---
scope_sim param_logic(spam);
param_logic.Scale_Thickness(col_height*10.0);
//Set slice thickness to be an integer divider of the total column height
//(parameter = per unit cell). Assumes orthorhombic box described in Angstroms.
//This function also sets the slice count needed for this thickness.
param_logic.Get_Parameters(spam);
out_file << line_feed << "slice-thickness: " << spam.slice_thickness;
//Slice thickness for potential projection in multislice calculation.
out_file << line_feed << "slices: " << spam.slice_count;
//Number of slices to span the total column height.
out_file << line_feed << "center slices: yes % centering is the way to go";
//Try to position slices such that they are close to atomic planes.
out_file << line_feed << "slices between outputs: " << spam.slice_output_count;
//Interval of slices simulated before a new image is made from the
//electron wavefunction (e.g. make image every 10 slices = 30 Angstroms).
out_file << line_feed << line_feed << "xOffset: 0.000";
out_file << line_feed << "yOffset: 0.000";
out_file << line_feed << "zOffset: 0.000";
//Potential offsets.
out_file << line_feed << "periodicXY: no";
out_file << line_feed << "periodicZ: no";
//Periodicity of slices. Assume none.
//Scanning window information---
if ( (spam.scope_mode == STEM_MODE) || (spam.scope_mode == CBED_MODE) )
//Scan window. Describes the rastering of the STEM beam probe
//across the specimen.
{
out_file << line_feed << line_feed << "%%%%%%%SCAN WINDOW%%%%%%";
out_file << line_feed << line_feed << "scan_x_start: " << spam.scan_x_min;
out_file << line_feed << "scan_x_stop: " << spam.scan_x_max;
out_file << line_feed << line_feed << "scan_x_pixels: " << spam.raster_x;
out_file << line_feed << "scan_y_start: " << spam.scan_y_min;
out_file << line_feed << "scan_y_stop: " << spam.scan_y_max;
out_file << line_feed << "scan_y_pixels: " << spam.raster_y;
}
//Detector information---
if (spam.scope_mode == STEM_MODE)
//STEM detectors. Supports up to two detectors.
{
out_file << line_feed << line_feed << "%%%%%%%%STEM DETECTORS%%%%%%";
out_file << line_feed << line_feed << "detector: "
<< spam.detector_inner_angle << " "
<< spam.detector_outer_angle << " detector1 0.000 0.000";
//No detector offsets used.
if (!Check_FP_Equality(spam.detector_outer_angle2, 0.0))
//Second detector can be turned off by a zero outer angle value.
{
out_file << line_feed << "detector: "
<< spam.detector_inner_angle2 << " "
<< spam.detector_outer_angle2 << " detector2 0.000 0.000";
}
}
//Geometric information---
out_file << line_feed << line_feed << "%%%%%%GEOMETRIC PROPERTIES%%%%%%%%%";
out_file << line_feed << line_feed << "Crystal tilt X: " << spam.tilt_x * PI_CONST/180.0;
out_file << line_feed << "Crystal tilt Y: " << spam.tilt_y * PI_CONST/180.0;
out_file << line_feed << "Crystal tilt Z: " << spam.tilt_z * PI_CONST/180.0;
//Sample tilt, in radians.
out_file << line_feed << "Beam tilt X: " << spam.beam_tilt_x;
out_file << line_feed << "Beam tilt Y: " << spam.beam_tilt_y;
//Beam tilt, in degrees.
out_file << line_feed << "Tilt back: no";
//Imaging mode properties---
out_file << line_feed << line_feed << "%%%%%%IMAGING MODE PARAMETERS%%%%%%%%%";
out_file << line_feed << line_feed << "nx: " << param_logic.Probe_Array_Size_X();
out_file << line_feed << "ny: " << param_logic.Probe_Array_Size_Y();
//Number of points sampled in the virtual electron beam.
//For example, 200 x 200 points in the beam with a spatial resolution of
//0.05 A corresponds to a 10 x 10 A size for the virtual probe description.
out_file << line_feed << "Cs: " << spam.Cs3;
out_file << line_feed << "C5: " << spam.Cs5;
out_file << line_feed << "Cc: " << spam.Cc;
out_file << line_feed << "dV/V: " << param_logic.Rel_Energy_Spread();
//Aberrations.
out_file << line_feed << "alpha: " << spam.convergence_angle;
out_file << line_feed << "defocus: " << spam.defocus;
//Beam convergence angle and defocus.
out_file << line_feed << "astigmatism: " << spam.two_astig;
out_file << line_feed << "astigmatism angle: " << spam.two_astig_angle;
out_file << line_feed << "a_33: " << spam.three_astig*10.0;
out_file << line_feed << "phi_33: " << spam.three_astig_angle;
//More aberrations.
out_file << line_feed << line_feed << line_feed
<< "Source Size (diameter): " << spam.source_size;
//Electron gun size (FWHM).
out_file << line_feed << "beam current: " << spam.current;
//Electrical current in beam.
out_file << line_feed << "dwell time: " << spam.dwell_time/1000.0;
//Amount of time spent gathering one pixel in a STEM image.
out_file << line_feed << "smooth: yes";
out_file << line_feed << "gaussian: no";
//Potential information/Other assorted information---
out_file << line_feed << line_feed << "%%%%%%POTENTIAL PARAMETERS%%%%%%%%%%";
out_file << line_feed << line_feed << "potential3D: yes";
out_file << line_feed << "atom radius: 5.0";
//Atom radius used in QSTEM graphical display.
out_file << line_feed << "plot V(r)*r: no";
out_file << line_feed << "bandlimit f_trans: no";
out_file << line_feed << "save potential: no";
out_file << line_feed << "saves projected potential: no";
out_file << line_feed << "one time integration: yes";
out_file << line_feed << "Display Gamma: 0";
out_file << line_feed << "Folder: \"" << test_folder_name << '\"';
//Output folder for image simulation results.
out_file << line_feed << "Runs for averaging: " << spam.TDS_runs;
//Number of TDS runs averaged to get the final image.
out_file << line_feed << "Structure Factors: WK ";
out_file << line_feed << "show Probe: no";
out_file << line_feed << "propagation progress interval: 10";
out_file << line_feed << "potential progress interval: 1000";
out_file << line_feed << "update Web: no";
//Do not update my website.
out_file << line_feed << "Pendelloesung plot: no";
out_file << line_feed << "sequence: 1 1";
out_file.close();
}
void Write_QPBS_File(const char* Wfile_name, const char* qstem_ext)
{
char line_feed = char(10);
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
char system_name[100];
Copy_With_No_Extension(system_name, Wfile_name);
Remove_Root(system_name);
//Use the file name without the extension as the test name.
char qfile_name[100];
strcpy(qfile_name, system_name);
Add_File_Extension(qfile_name, qstem_ext);
out_file << "#!/bin/bash" << line_feed
<< "#PBS -lnodes=1:ppn=1" << line_feed
<< "#PBS -N " << system_name << line_feed
<< line_feed
<< "cd $PBS_O_WORKDIR" << line_feed
<< line_feed
<< ". /etc/profile.d/modules.sh" << line_feed
<< line_feed
<< "module load qstem" << line_feed
<< "mpirun -n 1 stem3 " << qfile_name;
}
}
void Write_JEMS_File(const atom_collection& atoms, const char* Wfile_name,
bool include_hydro, bool include_DWF)
{
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
out_file.precision(7);
char system_name[100];
Copy_With_No_Extension(system_name, Wfile_name);
//Use the file name without the extension as the test name.
//Header lines---
out_file << "file|/" << Wfile_name << endl;
//File name header.
out_file << "name|" << system_name << endl;
//System name.
out_file << "creator|DWNBRF_FileGenerator" << endl;
//Creator name (David Welch-Nigel Browning-Roland Faller File Generator).
time_t date;
time (&date);
out_file << "date|" << ctime(&date) << endl;
//Time stamp.
//Structural information---
double cell_vec[3];
atoms.Get_Box_Vectors(cell_vec);
out_file << "system|triclinic" << endl;
out_file << "superCell|true" << endl;
out_file << "HMSymbol|1|1|0|0| P 1" << endl;
//Symmetry information.
out_file << "rps|0| x , y , z" << endl;
out_file << "lattice|0|" << cell_vec[0] << endl;
out_file << "lattice|1|" << cell_vec[1] << endl;
out_file << "lattice|2|" << cell_vec[2] << endl;
out_file << "lattice|3|90.0" << endl;
out_file << "lattice|4|90.0" << endl;
out_file << "lattice|5|90.0" << endl;
//Supercell structural information (assumes orthorhombic cell).
//Loading of DWF factors if needed---
const int MAX_INDEX = 100;
double** dwf_vals;
if (include_DWF)
{
Get_Memory(dwf_vals, MAX_ATOMIC_NUMBER, MAX_INDEX);
//Get the Debye-Waller factors from file.
Load_DW_Factors(dwf_vals);
}
//Atom listing---
double coors[3];
char temp_atom_name[MAX_ANAME_SIZE];
int actual_atom_count = 0;
//Used for indexing of atoms included in the JEMS file.
int atomic_number;
int atom_index;
for (int a = 0; a < atoms.Size(); ++a)
//Atom-by-atom information.
{
if (!atoms[a].Is_Invisible(include_hydro))
{
atoms[a].Get_Atom_Location(coors);
atoms[a].Get_Atom_Name(temp_atom_name);
out_file << "atom|" << actual_atom_count << '|' << temp_atom_name
<< ",_," << coors[0]/cell_vec[0] << ','
<< coors[1]/cell_vec[1] << ',' << coors[2]/cell_vec[2]
<< ',';
//Coordinates given relative to the orthorhombic box.
out_file.precision(3);
out_file << fixed;
if (!include_DWF)
//Default line.
{
out_file << "0.005,1.000,0.100,Def,0" << endl;
}
else
//Include DWFs.
{
atomic_number = atoms[a].Get_Atom_Number();
atom_index = Get_Number(temp_atom_name);
out_file << dwf_vals[atomic_number][atom_index]
<< ",1.000,0.100,Def,0" << endl;
}
++actual_atom_count;
}
}
if (include_DWF)
{
Free_Memory(dwf_vals, MAX_ATOMIC_NUMBER);
}
out_file.close();
}
}
//Analysis files---
void Write_RAD_File(const atom_collection& atoms, const char* Wfile_name,
double integration_interval)
//g(r) = [ (#atoms/shell interval r1 to r2) / (4*PI*ravg*ravg*(r2-r1)) ]
// / (Npairs/V)
{
const double MAX_DISTANCE = 1.0;
//Maximum distance analyzed in RDF = 10 Angstroms.
int num_steps = int(MAX_DISTANCE/integration_interval) + 1;
//Number of integrations to perform to get the whole RDF
//from 0 to 10 Angstroms.
char** atom_names;
Get_Memory(atom_names, MAX_ATOM_TYPES, MAX_ANAME_SIZE);
//List of atom names, one per atom types.
int num_atom_types;
//Number of atom names in the system.
atoms.Get_Name_List(atom_names, num_atom_types, MAX_ATOM_TYPES);
//Get a list of all names in the atomic collection (e.g. Si, N, etc.).
char* atomA;
char* atomB;
//Temp pointers to the atom name pair being considered in one
//RDF calculation. E.g. O-Si has name pair of O and Si.
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
double* distances_tested = new double[num_steps];
//X-axis distances to analyze in integration.
double* RDF_values = new double[num_steps];
//Y-axis values of the RDF at those x-axis distances.
for (int a = 0; a < num_steps; ++a)
//Initialize their values.
{
distances_tested[a] = double(a) * integration_interval;
RDF_values[a] = 0.0;
}
for (int a = 0; a < num_atom_types; ++a)
{
atomA = atom_names[a];
for (int b = a; b < num_atom_types; ++b)
//For each atom name pair that can be considered...
{
atomB = atom_names[b];
atoms.Calculate_RDF(atomA, atomB, RDF_values, integration_interval);
//Calculate the RDF for the given atom pair.
out_file << "Radial distribution function: " << endl;
out_file << endl << atomA << "-" << atomB;
//Introduce the atom pair.
for (int a = 0; a < num_steps; ++a)
//Output values.
{
out_file << endl << distances_tested[a] << " " << RDF_values[a];
}
out_file << endl << endl << endl;
}
}
delete[] RDF_values;
delete[] distances_tested;
Free_Memory(atom_names, MAX_ATOM_TYPES);
out_file.close();
}
}
void Write_DISTCOUNT_File(const atom_collection& atoms, const char* Wfile_name,
double count_region, bool include_hydro)
{
const double DISTANCE_RANGE_MIN = 0.0;
const double DISTANCE_RANGE_MAX = 1.0;
//Length of sampling region, from 0 to 10 A.
const double DISTANCE_SPAN = DISTANCE_RANGE_MAX - DISTANCE_RANGE_MIN;
double bin_size = count_region;
//Length of counting regions.
int num_bins = int(DISTANCE_SPAN/count_region) + 1;
//Fill the bins and output the number of distance elements
//in each bin---
ofstream out_file(Wfile_name, ios::out);
if (out_file.is_open())
{
double* distances_tested = new double[num_bins];
//X-axis values/bin locations in distance space.
int* counts = new int[num_bins];
//Y-axis values/number of elements in each bin.
for (int a = 0; a < num_bins; ++a)
//Initialize values.
{
distances_tested[a] = DISTANCE_RANGE_MIN + double(a) * bin_size;
}
out_file << "Distance counts: " << endl;
for (int a = 0; a < (num_bins - 1); ++a)
//Fill each bin.
{
counts[a] = atoms.Pair_Count(distances_tested[a],
distances_tested[a + 1], FALSEV, FALSEV, include_hydro);
//Count the number of distances in the distance region represented by
//the bin being considered.
out_file << endl << " Distance Range of " << distances_tested[a] << " to "
<< distances_tested[a + 1] << " has " << counts[a] << " pairs.";
}