-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransition.java
More file actions
401 lines (375 loc) · 11.2 KB
/
Copy pathTransition.java
File metadata and controls
401 lines (375 loc) · 11.2 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
package plotCAS;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Transition {
/* Molcas specific */
public int fromGS=1;
public int toGS=1;
public float Boltztemp=0;
public boolean isdipole=false;
public boolean isquadrupole=false;
public boolean isveloc=false;
public boolean isboltz=false;
public boolean isSF=false;
public boolean isSOC=false;
public boolean isETMO=false;
private Molcasfile molcas;
/* General */
private File transitionfile;
public int ntrans;
private Window window;
/* List input */
public Transition(Window tmp,String text)
{
window=tmp;
transfile(tmp.ncurve,tmp.WorkDir);
put_to_file(transitionfile,text);
}
public Transition(Window tmp)
{
window=tmp;
transfile(tmp.ncurve,tmp.WorkDir);
}
/* MOLCAS input */
public Transition(Window tmp,Molcasfile input,boolean dSF, boolean dSOC, boolean ddip, boolean dveloc,boolean dquad, boolean dETMO,boolean dboltz, float dtemp,int i1,int i2)
{
window=tmp;
molcas=input;
isSF=dSF;
isSOC=dSOC;
isdipole=ddip;
isveloc=dveloc;
isETMO=dETMO;
isquadrupole=dquad;
Boltztemp=dtemp;
isboltz=dboltz;
fromGS=i1;
toGS=i2;
transfile(tmp.ncurve,tmp.WorkDir);
input.totransition(tmp.plot.getunit(),dSF, dSOC, ddip, dveloc, dquad, dETMO,dboltz, dtemp, transitionfile,i1,i2);
}
/* ******************************** */
/* ******* Analysis ******** */
/* ******************************** */
public void analysis(String parentname,int mode)
{
Window tmp=window;
/* Make list of SOC states for screening */
//int[] SOClist=new int[1];
//int jtrans=0;
/* if (isSOC)
{
SOClist = new int[ntrans+toGS-fromGS+1]; // max possible number of states
for (int itrans = 0; itrans < toGS-fromGS+1; itrans++)
{
SOClist[itrans]=fromGS+itrans;
}
try {
BufferedReader reader = new BufferedReader(new FileReader(transitionfile));
String text;
int i1;
for (int itrans = 0; itrans < ntrans; itrans++)
{
text = reader.readLine();
i1=Integer.parseInt(text.trim().split(" +")[2]);
SOClist[itrans+toGS-fromGS+1]=i1;
}
reader.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(new JFrame(), "Internal I/O error", "Error",JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
java.util.Arrays.sort( SOClist );*/
/* Remove doublons */
/*for (int itrans = 1; itrans < ntrans+toGS-fromGS+1; itrans++)
{
if (SOClist[itrans]!=SOClist[jtrans])
{
jtrans++;
if (itrans!=jtrans) {SOClist[jtrans]=SOClist[itrans];}
}
}
}
else
{*/
if (isSOC)
{
JOptionPane.showMessageDialog(new JFrame(), "Spin-orbit spectra analysis temporarily disabled", "Error",JOptionPane.ERROR_MESSAGE);
}
else
{
/* Get natural orbitals */
int ntact;
if (mode==0) {ntact=molcas.ntact;}
else {ntact=molcas.nspin;}
int nrSFstates=molcas.nrSFstates;
float[][] natorb=new float[nrSFstates][ntact];
Transition[] trans=new Transition[ntact];
File[] inpfile=new File[ntact];
BufferedWriter[] writer = new BufferedWriter[ntact];
if (mode==0) {natorb=molcas.orbocc();}
else {natorb=molcas.spinocc();}
/* Plot differences */
try {
BufferedReader reader = new BufferedReader(new FileReader(transitionfile));
for (int iorb =0; iorb < ntact; iorb++)
{
trans[iorb]=new Transition(tmp);
tmp.ncurve++;
inpfile[iorb]=trans[iorb].getfile();
writer[iorb]= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(inpfile[iorb]), "utf-8"));
}
tmp.ncurve-=ntact;
String text;
int i1,i2;
float e1,e2,intens;
for (int itrans = 0; itrans < ntrans; itrans++)
{
text = reader.readLine();
e1=Float.parseFloat(text.trim().split(" +")[0]);
e2=Float.parseFloat(text.trim().split(" +")[1]);
i2=Integer.parseInt(text.trim().split(" +")[2])-1;
i1=Integer.parseInt(text.trim().split(" +")[3])-1;
for (int iorb =0; iorb < ntact; iorb++)
{
intens=e2*(natorb[i2][iorb]-natorb[i1][iorb]);
writer[iorb].write(String.valueOf(e1)+" "+String.valueOf(intens)+"\n");
}
}
reader.close();
for (int j=0; j<ntact; j++)
{
writer[j].write("#"+String.valueOf(ntrans));
writer[j].close();
String curvename=parentname+" "+molcas.orblabel[j];
tmp.addcurve(curvename,1,trans[j],"",tmp.plot.getunit());
}
} catch (Exception e) {
JOptionPane.showMessageDialog(new JFrame(), "Internal I/O error", "Error",JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
}
/* ******************************** */
/* ******* Scattering ******** */
/* ******************************** */
public float[][] scatterplane(float e1i,float e2i,float e1t,float e2t, int xres,int yres,int iunit,boolean isbefore)
{
float Escale=(float) Curveplot.unitfactor(iunit);
/* Store initial->intermediate transitions */
int nstates=0;
String stop="*SF";
if (isSF) { nstates=molcas.getSFstates(); stop="*SF";}
else { nstates=molcas.getSOCstates(); stop="*SOC";}
int[] position = new int[nstates];
for (int istate = 0; istate < nstates; istate++) { position[istate]=-1;}
float[] tenergy = new float[ntrans];
float[] intensity = new float[ntrans];
float[] senergy = new float[nstates];
String text;
int i1=0,i2;
float ene,intens;
int ninter=-1;
// Right now only work only for degenerate ground states
try {
BufferedReader reader = new BufferedReader(new FileReader(transitionfile));
text="";
for (int itrans = 0; itrans < ntrans; itrans++)
{
text = reader.readLine();
ene=Float.parseFloat(text.trim().split(" +")[0]);
if (ene>e1i&&ene<e2i)
{
i2=Integer.parseInt(text.trim().split(" +")[2])-1;
if (position[i2]<0)
{
ninter++;
intens=Float.parseFloat(text.trim().split(" +")[1]);
if (intens<=0) continue;
tenergy[ninter]=ene;
if (isbefore) {
intensity[ninter]=3/2*intens/(ene/Escale);
}
else{
intensity[ninter]=(float) Math.sqrt(3/2*intens/(ene/Escale));
}
position[i2]=ninter;
}
else
{
int ipos=position[i2];
if (Math.abs(tenergy[ipos]-ene)>(e2i-e1i)/xres)
{
JOptionPane.showMessageDialog(new JFrame(), "Scattering plots not implemented for non-degenerate ground states", "Error",JOptionPane.ERROR_MESSAGE);
break;
}
else
{
intens=Float.parseFloat(text.trim().split(" +")[1]);
if (intens<=0) continue;
if (isbefore) {
intensity[ipos]+=3/2*intens/(ene/Escale);
}
else {
intensity[ipos]+=(float) Math.sqrt(3/2*intens/(ene/Escale));
}
}
}
}
}
i1=Integer.parseInt(text.trim().split(" +")[3])-1;
reader.close();
reader = new BufferedReader(new FileReader(molcas.getFile()));
while ((text = reader.readLine()) != null) {
/* Store state energies */
if (text.contains(stop))
{
for (int i = 0; i < nstates; i++)
{
text = reader.readLine();
senergy[i]=Float.parseFloat(text.trim().split(" +")[0]);
}
break;
}
}
reader.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(new JFrame(), "Internal I/O error", "Error",JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
/* Find the first and last final states (sadly they are not necessarily energy ordered)*/
float e0=senergy[i1];
boolean first=true;
int ifirst=0,ilast=0;
for (int i = 0; i < nstates; i++)
{
ene=Escale*(senergy[i]-e0);
if ((ene>=e1t)&&(ene<e2t))
{
if (first)
{
first=false;
ifirst=i;
}
ilast=i;
}
}
int nfinal=ilast-ifirst+1;
float[][] plane = new float[xres+1][nfinal];
for (int i = 0; i < xres; i++) {for (int j = 0; j < nfinal; j++) {plane[i][j]=0;}}
for (int j = 0; j < nfinal; j++) {plane[xres][j]=Escale*(senergy[ifirst+j]-e0);}
try {
BufferedReader reader = new BufferedReader(new FileReader(molcas.getFile()));
boolean passed=false;
while ((text = reader.readLine()) != null) {
/* Store state energies */
if (text.contains(stop))
{
passed=true;
text = reader.readLine();
}
if (text.contains("*SOC"))
{
passed=false;
}
/* Read through transitions */
if (passed&&((text.contains("*Velocity")&&isdipole&&isveloc)||(text.contains("*Dipole")&&isdipole&&!isveloc)||(text.contains("*Quadrupole")&&isquadrupole)||(text.contains("*ETMO")&&isETMO)))
{
int x,y;
text = reader.readLine();
float dE;
while (!text.startsWith("*"))
{
i1=Integer.parseInt(text.trim().split(" +")[0])-1;
i2=Integer.parseInt(text.trim().split(" +")[1])-1;
intens=Float.parseFloat(text.trim().split(" +")[2]);
if (intens<=0) { text = reader.readLine();continue;}
if (position[i1]>=0)
{
ene=tenergy[position[i1]]-Escale*(senergy[i1]-senergy[i2]);
if ((ene>=e1t)&&(ene<e2t))
{
dE=senergy[i1]-senergy[i2];
if (dE>0)
{
dE=(float) Math.max(dE,0.0001);
if (isbefore) {
intens=3/2*intens/dE;
}
else {
intens=(float) Math.sqrt(3/2*intens/dE);
}
intens=intens*intensity[position[i1]];
x=(int) ((tenergy[position[i1]]-e1i)/(e2i-e1i)*(float)xres);
//y=(int) ((ene-e1t)/(e2t-e1t)*(float)yres);
y=i2-ifirst;
plane[x][y]+=intens;
}
}
}
if (position[i2]>=0)
{
ene=tenergy[position[i2]]-Escale*(senergy[i2]-senergy[i1]);
if ((ene>=e1t)&&(ene<e2t))
{
dE=senergy[i2]-senergy[i1];
if (dE>0)
{
dE=(float) Math.max(dE,0.0001);
if (isbefore) {
intens=3/2*intens/dE;
}
else {
intens=(float) Math.sqrt(3/2*intens/dE);
}
intens=intens*intensity[position[i2]];
x=(int) ((tenergy[position[i2]]-e1i)/(e2i-e1i)*(float)xres);
//y=(int) ((ene-e1t)/(e2t-e1t)*(float)yres);
y=i1-ifirst;
plane[x][y]+=intens;
}
}
}
text = reader.readLine();
}
}
}
reader.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(new JFrame(), "Internal I/O error", "Error",JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
return plane;
}
/* Gets, sets and utils */
public Molcasfile getmolcas()
{
return molcas;
}
public File getfile() {
return transitionfile;
}
public void put_to_file(File pfile,String ptext){
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(pfile), "utf-8"));
writer.write(ptext);
writer.close();
} catch (IOException ex) {
JOptionPane.showMessageDialog(new JFrame(), "Failed to save this file", "Error",JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
}
private void transfile(int ncurve,File WorkDir)
{
String filename="curve"+String.valueOf(ncurve+1)+".xy";
transitionfile=new File (WorkDir,filename);
}
}