-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaussianInputFile.java
115 lines (102 loc) · 4.5 KB
/
GaussianInputFile.java
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
import java.io.*;
import java.util.*;
import org.apache.commons.math3.geometry.euclidean.threed.*;
import org.jgrapht.*;
import org.jgrapht.graph.*;
import org.jgrapht.alg.*;
/** Represent a Gaussian input file for debugging purposes. */
public class GaussianInputFile extends InputFileFormat
{
public GaussianInputFile(Molecule molecule)
{
super(getGaussianString(molecule,molecule.name,""));
}
public GaussianInputFile(Molecule molecule, String name)
{
super(getGaussianString(molecule,name,""));
}
public GaussianInputFile(Molecule molecule, String name, String keywords)
{
super(getGaussianString(molecule,name,keywords));
}
public GaussianInputFile(Molecule molecule, Set<Atom> includeAtoms)
{
super(getGaussianString(molecule,includeAtoms));
}
private static String getGaussianString(Molecule molecule, String name, String keywords)
{
String returnString = "%mem=1GB\n%nprocshared=12\n#p geom=connect " + keywords + "\n";
returnString += "\n" + name + "\n\n0 1\n";
returnString = returnString + molecule.toOmnisolString() + "\n";
Atom fromAtom = null;
Atom toAtom = null;
Integer fromAtomNumber = 0;
Integer toAtomNumber = 0;
Double bondOrder = 0.0;
DefaultWeightedEdge thisEdge = null;
// read connectivity data into parallel arrays
ArrayList<Integer> fromAtoms = new ArrayList<Integer>();
ArrayList<Integer> toAtoms = new ArrayList<Integer>();
ArrayList<Double> bondOrders = new ArrayList<Double>();
ArrayList<Boolean> visited = new ArrayList<Boolean>();
for (DefaultWeightedEdge e : molecule.connectivity.edgeSet())
{
fromAtom = molecule.connectivity.getEdgeSource(e);
fromAtomNumber = molecule.contents.indexOf(fromAtom) + 1;
toAtom = molecule.connectivity.getEdgeTarget(e);
toAtomNumber = molecule.contents.indexOf(toAtom) + 1;
bondOrder = molecule.connectivity.getEdgeWeight(e);
fromAtoms.add(fromAtomNumber);
toAtoms.add(toAtomNumber);
bondOrders.add(bondOrder);
visited.add(false);
}
for (int i=0; i < molecule.contents.size(); i++)
{
returnString = returnString + (i+1) + " ";
for (int j=0; j < fromAtoms.size(); j++)
{
if (fromAtoms.get(j) == i+1 && visited.get(j) == false)
{
returnString = returnString + toAtoms.get(j) + " " + String.format("%.1f ", bondOrders.get(j));
visited.set(j, true);
}
if (toAtoms.get(j) == i+1 && visited.get(j) == false)
{
returnString = returnString + fromAtoms.get(j) + " " + String.format("%.1f ", bondOrders.get(j));
visited.set(j, true);
}
}
returnString = returnString + "\n";
}
returnString = returnString + "\n\n";
return returnString;
}
/**
* Writes a gjf file that only includes part of the molecule.
* @param molecule the molecule whose geometry we want to write partially
* @param includeAtoms the atoms to include the result
* @return a String containing a gjf that only includes includeAtoms
*/
private static String getGaussianString(Molecule molecule, Set<Atom> includeAtoms)
{
String returnString = "%mem=1GB\n%nprocshared=12\n#p geom=connect\n";
returnString += "\nname\n\n0 1\n";
List<Atom> newContents = new LinkedList<>();
Set<Atom> excludedAtoms = new HashSet<>();
for (Atom a : molecule.contents)
{
if ( includeAtoms.contains(a) )
newContents.add(a);
else
excludedAtoms.add(a);
}
Collections.sort(newContents);
Molecule tempMolecule = molecule.moveAtoms(new HashMap<Atom,Atom>());
SimpleWeightedGraph<Atom,DefaultWeightedEdge> connectivity = tempMolecule.connectivity;
for (Atom a : excludedAtoms)
connectivity.removeVertex(a);
Molecule tempMolecule2 = new Molecule(molecule.name, newContents, connectivity);
return getGaussianString(tempMolecule2, molecule.name, "");
}
}