Skip to content

Commit

Permalink
Fix gaussian input parser, and add test (#4127)
Browse files Browse the repository at this point in the history
  • Loading branch information
sio-salt authored Oct 21, 2024
1 parent 91f12de commit 52eeeea
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pymatgen/io/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ def from_str(cls, contents: str) -> Self:
route += f" {line}"
route_index = idx
# This condition allows for route cards spanning multiple lines
elif (line == "" or line.isspace()) and route_index:
elif (line == "" or line.isspace()) and route_index is not None:
break
if route_index:
if route_index is not None:
route += f" {line}"
route_index = idx
functional, basis_set, route_paras, dieze_tag = read_route_line(route)
Expand Down
69 changes: 69 additions & 0 deletions tests/files/io/gaussian/C60_gau.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#p M062X/cc-pVDZ GFPrint Pop=Full
Guess=Huckel Scfcyc=1500 SCF=Tight
6D Int(Grid=UltraFine)

M06-2X Gaussian C60 Ih

0 1
C -0.610401176921 0.810029720944 -0.764305079403
C -1.192040230402 2.057349251447 -0.954889339744
C -2.550768816579 2.301728679891 -0.503345793607
C -3.268831998991 1.288172163417 0.119165904258
C -2.660777640865 -0.015794741763 0.318405603513
C -1.361075404971 -0.249557755793 -0.113521834011
C -4.669739264514 1.085143064631 -0.206401705392
C -4.927493211517 -0.344302724279 -0.208373854526
C -3.685886645977 -1.024719708115 0.115974899928
C -5.291724656777 1.904490541619 -1.140337593858
C -6.199711641198 1.331603130650 -2.118660598022
C -6.446268153344 -0.035744187164 -2.120547072368
C -5.796035115872 -0.892302565114 -1.144196217325
C -4.541050428727 2.964078018356 -1.791120839251
C -3.201001854051 3.158287057841 -1.479696648649
C -5.462415534693 -2.145606959850 -1.798170466963
C -4.274747264674 -2.796465037103 -1.487912181554
C -3.366760280445 -2.223577626213 -0.509589177552
C -2.008031694237 -2.467957054545 -0.961132723659
C -1.027455824014 -1.502862150563 -0.767496083695
C 0.187160591378 0.211586400804 -1.820485494071
C -0.070593355760 -1.217859388082 -1.822457643160
C -2.076278230991 -3.191879258295 -2.218524986693
C -3.477185496519 -3.394908357080 -2.544092596317
C -5.906460331781 -2.063633296247 -3.178699636034
C -6.514514689934 -0.759666390974 -3.377939335377
C -6.010204230835 2.037126715691 -3.374080711915
C -4.985095225753 3.046051682028 -3.171650008337
C -2.244139385630 3.443289820289 -2.534658208103
C -1.002532820230 2.762872836487 -2.210309453667
C -0.239619002072 2.190427295005 -3.220606918823
C 0.368435356055 0.886460389826 -3.021367219568
C -0.135875103403 -1.910332716805 -3.025225842953
C -1.160984108672 -2.919257683102 -3.227656546400
C -3.901939948213 -3.316495821242 -3.864648346745
C -5.143546513762 -2.636078837446 -4.188997101249
C -6.333239925080 -0.084792401885 -4.578821060810
C -6.075485978123 1.344653386901 -4.576848911688
C -4.069801102713 3.318673257346 -4.180781568144
C -2.668893837362 3.521702356144 -3.855213958518
C -1.871332068979 2.923259035966 -4.911394373101
C -0.683663799358 2.272400958676 -4.601136087826
C 0.300188819054 0.162538185986 -4.278759482538
C 0.053632306775 -1.204809131727 -4.280645956853
C -1.605028905935 -2.837284019301 -4.608185715402
C -2.945077480671 -3.031493058655 -4.919609905823
C -4.954039103506 -1.930555252450 -5.444417215184
C -5.535678156438 -0.683235721865 -5.635001475308
C -5.118623509630 1.629656149468 -5.631810471044
C -4.138047639389 2.594751053411 -5.438173831076
C -2.779319053535 2.350371625022 -5.889717377153
C -0.350044218472 1.019096563840 -5.255110337422
C -0.854354677887 -1.777696542576 -5.258968960863
C -3.595310518635 -2.174934680895 -5.895960760705
C -4.785003928524 0.376351754708 -6.285784720673
C -3.485301692568 0.142588740749 -6.717712158047
C -2.460192688139 1.151513706802 -6.515281454472
C -1.218586123107 0.471096723020 -6.190932700028
C -1.476340070226 -0.958349065502 -6.192904849203
C -2.877247335830 -1.161378164125 -6.518472458604


27 changes: 27 additions & 0 deletions tests/io/test_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ def test_from_str(self):
assert gau.molecule.composition.reduced_formula == "X3SiH4"
assert set(gau.route_parameters) == {"opt", "freq", "scf"}

def test_from_str_no_link0(self):
gau_str = """#p mp2/6-31g* scf=direct
opt freq
SIH4+ H2---SIH2+ CS //MP2(full)/6-31G* MP2=-290.9225259
1,2
Si
X,1,1.
H,1,R1,2,HALF1
H,1,R1,2,HALF1,3,180.,0
X,1,1.,2,90.,3,90.,0
X,1,1.,5,THETA,2,180.,0
H,1,R3,6,HALF3,5,0.,0
H,1,R4,6,HALF3,7,180.,0
R1=1.47014
R3=1.890457
R4=1.83514
HALF1=60.633314
THETA=10.35464
HALF3=11.861807"""

gau = GaussianInput.from_str(gau_str)
assert gau.molecule.composition.reduced_formula == "X3SiH4"
assert set(gau.route_parameters) == {"opt", "freq", "scf"}

def test_gen_basis(self):
gau_str = """#N B3LYP/Gen Pseudo=Read
Expand Down

0 comments on commit 52eeeea

Please sign in to comment.