-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
156 lines (128 loc) · 5.09 KB
/
main.c
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
/** ***************************************************** **/
/** ** Phonon Vibration Analysis ** **/
/** **/
/** ** Version 2 ** **/
/** **/
/** By: Pedro Brandimarte (brandimarte@gmail.com) and **/
/** Alexandre Reily Rocha (reilya@ift.unesp.br) **/
/** **/
/** ***************************************************** **/
/** This is a (client) program that reads the output data **/
/** from a siesta force constants (FC) calculation runned **/
/** with the flag 'PB.FCwriteHS .true.' at the fdf input **/
/** file. Computes the phonon energies and modes, the **/
/** hamiltonian derivatives with respect to the dynamic **/
/** atoms displacements and computes the electron-phonon **/
/** coupling matrix. **/
/** ***************************************************** **/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "Utils.h"
#include "Phonon.h"
/* Prints the header on the screen. */
static void header ();
/* Prints the "how to run" on the screen. */
static void howto ();
int main (int nargs, char *arg[])
{
int nDynTot, nDynOrb, spinPol, calcType;
double *EigVec, *EigVal, *Meph;
double time;
clock_t inicial, final;
/* Writes the header on the screen. */
header ();
/* Checks if the input were typed correctly. */
if (nargs < 4 || nargs > 5) {
fprintf (stderr, "\n Wrong number of arguments!\n");
howto ();
exit (EXIT_FAILURE);
}
/* Time is running. */
inicial = clock();
/* Checks calculation option (full or onlyPh). */
if (strcmp (arg[3], "full") == 0)
calcType = 1;
else {
if (strcmp (arg[3], "onlyPh") == 0)
calcType = 2;
else {
fprintf (stderr, "\n Wrong calculation type option!\n");
fprintf (stderr, "\n It must be 'full' or 'onlyPh'.\n");
howto ();
exit (EXIT_FAILURE);
}
}
/* Reads info from FC fdf input file. */
if (nargs == 4)
PHONreadFCfdf (arg[0], arg[1], arg[2], calcType, " ",
&nDynTot, &nDynOrb, &spinPol);
else
PHONreadFCfdf (arg[0], arg[1], arg[2], calcType, arg[4],
&nDynTot, &nDynOrb, &spinPol);
/* Computes phonon frequencies. */
EigVec = UTILdoubleVector (nDynTot * nDynTot);
EigVal = UTILdoubleVector (nDynTot);
PHONfreq (EigVec, EigVal);
/* Writes a 'xyz' file for each computed phonon mode. */
PHONjmolVib (EigVec);
/* At "onlyPh" calculations it is finished. */
if (calcType == 2) {
/* Frees memory. */
free (EigVec);
free (EigVal);
/* Calculates the execution time. */
final = clock();
time = (double)(final - inicial) / CLOCKS_PER_SEC;
printf ("\n This calculation took %.2f seconds.\n\n", time);
return 0;
}
/* Computes electron-phonon coupling matrices. */
Meph = UTILdoubleVector (nDynOrb * nDynOrb * nDynTot * spinPol);
PHONephCoupling (EigVec, EigVal, Meph);
/* Frees memory. */
free (EigVec);
free (EigVal);
free (Meph);
/* Calculates the execution time. */
final = clock();
time = (double)(final - inicial) / CLOCKS_PER_SEC;
printf ("\n This calculation took %.2f seconds.\n\n", time);
return 0;
} /* main */
/* ********************************************************* */
/* Prints the header on 'stdout'. */
static void header ()
{
printf("\n");
printf("** ************************************************* **\n");
printf("** ** Phonon Vibration Analysis ** **\n");
printf("** **\n");
printf("** ** Version 1 ** **\n");
printf("** **\n");
printf("** By: Pedro Brandimarte (brandimarte@gmail.com) and **\n");
printf("** Alexandre Reily Rocha (reilya@ift.unesp.br) **\n");
printf("** **\n");
printf("** ************************************************* **\n");
printf("\n");
setvbuf (stdout, NULL, _IONBF, 0); /* print now! */
} /* PHONheader */
/* ********************************************************* */
/* Prints the "how to run" on 'stdout'. */
static void howto ()
{
fprintf (stderr, "\n Use: vibrations"); /* arg[0] */
fprintf (stderr, " [FC directory]"); /* arg[1] */
fprintf (stderr, " [FC input file]"); /* arg[2] */
fprintf (stderr, " [calculation type]"); /* arg[3] */
fprintf (stderr, " [splitFC]\n\n"); /* arg[4] */
fprintf (stderr,
" Examples : vibrations ~/MySystem/FCdir runFC.in full\n");
fprintf (stderr,
" vibrations ~/MySystem/FCdir runFC.in full splitFC\n");
fprintf (stderr,
" vibrations ~/MySystem/FCdir runFC.in onlyPh\n");
fprintf (stderr,
" vibrations ~/MySystem/FCdir runFC.in onlyPh splitFC\n\n");
} /* howto */