-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>ru.lesqm</groupId> | ||
<artifactId>TDDFTExcitationEnergiesFormatter</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>ru.lesqm.tddftexcitationenergies.formatter.Main</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
173 changes: 173 additions & 0 deletions
173
src/main/java/ru/lesqm/tddftexcitationenergies/formatter/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package ru.lesqm.tddftexcitationenergies.formatter; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.PrintWriter; | ||
import ru.lesqm.tddftexcitationenergies.formatter.models.TEERow; | ||
import java.util.ArrayList; | ||
import java.util.InputMismatchException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.NoSuchElementException; | ||
import java.util.Scanner; | ||
import ru.lesqm.tddftexcitationenergies.formatter.models.ExcitedState; | ||
import ru.lesqm.tddftexcitationenergies.formatter.models.ExcitedStateRow; | ||
|
||
public class Main { | ||
|
||
public static void usage() { | ||
System.out.println("Usage: format [flags] <input>"); | ||
System.out.println(" -a skip rows with % < 10"); | ||
System.exit(0); | ||
} | ||
|
||
public static void main(String[] args) throws FileNotFoundException { | ||
if (args.length < 2) { | ||
usage(); | ||
} | ||
|
||
boolean skipLw = false; | ||
|
||
String input = null; | ||
for (String a : args) { | ||
if (a.startsWith("-a")) { | ||
skipLw = true; | ||
} else { | ||
input = a; | ||
} | ||
} | ||
|
||
if (input == null) { | ||
usage(); | ||
} | ||
|
||
Scanner s = new Scanner(new FileInputStream(input)); | ||
s.useLocale(Locale.US); | ||
|
||
String str; | ||
|
||
System.out.print("Searching for 'RESULTS FROM SPIN-ADAPTED ANTISYMMETRIZED PRODUCT (SAPS)' title: "); | ||
while (!(str = s.nextLine()).trim().startsWith("RESULTS FROM SPIN-ADAPTED ANTISYMMETRIZED PRODUCT (SAPS)")) { | ||
} | ||
|
||
s.nextLine(); // Skip title 2 | ||
s.nextLine(); // Skip separator line | ||
s.nextLine(); // Skip empty line | ||
|
||
System.out.println("done"); | ||
|
||
List<ExcitedState> excitedStates = new ArrayList<>(); | ||
|
||
int stateNumber = 0; | ||
for (; s.hasNextLine(); stateNumber++) { | ||
|
||
System.out.print("Searching for 'EXCITED STATE ' title: "); | ||
try { | ||
while (!(str = s.nextLine()).trim().startsWith("EXCITED STATE ")) { | ||
} | ||
} catch (NoSuchElementException e) { | ||
break; | ||
} | ||
|
||
System.out.println("done"); | ||
|
||
String excitedStateString = str; | ||
|
||
s.nextLine(); // Skip empty line | ||
s.nextLine(); // Skip separator line | ||
s.nextLine(); // Skip header 1 | ||
s.nextLine(); // Skip header 2 | ||
s.nextLine(); // Skip separator line | ||
|
||
System.out.print("Parsing 'EXCITED STATE ...'" + "(" + (stateNumber + 1) + "):"); | ||
ExcitedState excitedState = new ExcitedState(); | ||
|
||
while (true) { | ||
try { | ||
ExcitedStateRow stateRow = new ExcitedStateRow(); | ||
|
||
stateRow.fromMo = s.nextInt(); | ||
stateRow.toMo = s.nextInt(); | ||
stateRow.sapCoefficient = s.nextDouble(); | ||
|
||
excitedState.rows.add(stateRow); | ||
} catch (NumberFormatException | InputMismatchException e) { | ||
break; | ||
} | ||
} | ||
|
||
excitedStates.add(excitedState); | ||
|
||
System.out.println("done"); | ||
} | ||
System.out.println("end of file"); | ||
|
||
s.close(); | ||
|
||
s = new Scanner(new FileInputStream(input)); | ||
s.useLocale(Locale.US); | ||
|
||
System.out.print("Searching for 'TDDFT EXCITATION ENERGIES' title: "); | ||
while (!(str = s.nextLine()).trim().equalsIgnoreCase("TDDFT EXCITATION ENERGIES")) { | ||
} | ||
|
||
s.nextLine(); // Skip header | ||
s.nextLine(); // Skip separator line | ||
|
||
System.out.println("done"); | ||
|
||
System.out.print("Parsing 'TDDFT EXCITATION ENERGIES' table: "); | ||
List<TEERow> teeRows = new ArrayList<>(); | ||
for (int i = 0; i < stateNumber; i++) { | ||
TEERow teerow = new TEERow(); | ||
|
||
teerow.state = s.next(); | ||
teerow.hartree = s.nextDouble(); | ||
teerow.hv = s.nextDouble(); | ||
teerow.kcalmol = s.nextDouble(); | ||
teerow.cm1 = s.nextDouble(); | ||
teerow.nanometers = s.nextDouble(); | ||
teerow.oscstr = s.nextDouble(); | ||
|
||
teeRows.add(teerow); | ||
} | ||
|
||
s.close(); | ||
System.out.println("done"); | ||
|
||
System.out.print("Writing result to 'result.out': "); | ||
|
||
PrintWriter pw = new PrintWriter(new FileOutputStream("result.out")); | ||
|
||
for (int i = 0; i < teeRows.size(); i++) { | ||
TEERow tee = teeRows.get(i); | ||
ExcitedState state = excitedStates.get(i); | ||
|
||
boolean first = true; | ||
for (ExcitedStateRow r : state.rows) { | ||
if (skipLw && (Math.pow(r.sapCoefficient, 2) * 100) < 10) { | ||
continue; | ||
} | ||
|
||
if (first) { | ||
first = false; | ||
pw.format("%s\t%d\t", tee.state, i + 1); | ||
} else { | ||
pw.format("\t\t"); | ||
} | ||
pw.format( | ||
"%d\t%d\t%d\t%d\t%f\n", | ||
r.fromMo, | ||
r.toMo, | ||
(int) Math.rint((Math.pow(r.sapCoefficient, 2d) * 100d)), | ||
(int) Math.rint(tee.nanometers), | ||
tee.oscstr); | ||
} | ||
} | ||
|
||
pw.close(); | ||
System.out.println("done"); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/ru/lesqm/tddftexcitationenergies/formatter/models/ExcitedState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ru.lesqm.tddftexcitationenergies.formatter.models; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ExcitedState { | ||
|
||
public int state; | ||
public double energy; | ||
public double s; | ||
public String spaceSym; | ||
|
||
public List<ExcitedStateRow> rows = new ArrayList<>(); | ||
|
||
@Override | ||
public String toString() { | ||
return "ExcitedState{" + "state=" + state + ", energy=" + energy + ", s=" + s + ", spaceSym=" + spaceSym + ", rows=" + rows + '}'; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/ru/lesqm/tddftexcitationenergies/formatter/models/ExcitedStateRow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ru.lesqm.tddftexcitationenergies.formatter.models; | ||
|
||
public class ExcitedStateRow { | ||
|
||
public int fromMo; | ||
public int toMo; | ||
public double sapCoefficient; | ||
|
||
@Override | ||
public String toString() { | ||
return "ExcitedStateRow{" + "fromMo=" + fromMo + ", toMo=" + toMo + ", sapCoefficient=" + sapCoefficient + '}'; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/ru/lesqm/tddftexcitationenergies/formatter/models/TEERow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package ru.lesqm.tddftexcitationenergies.formatter.models; | ||
|
||
/** | ||
* | ||
* @author User | ||
*/ | ||
public class TEERow { | ||
|
||
public String state; | ||
public double hartree; | ||
public double hv; | ||
public double kcalmol; | ||
public double cm1; | ||
public double nanometers; | ||
public double oscstr; | ||
|
||
@Override | ||
public String toString() { | ||
return "TEERow{" + "state=" + state + ", hartree=" + hartree + ", hv=" + hv + ", kcalmol=" + kcalmol + ", cm1=" + cm1 + ", nanometers=" + nanometers + ", oscstr=" + oscstr + '}'; | ||
} | ||
|
||
} |