Skip to content

Commit

Permalink
Try to fix tests due to allowing charge to be float.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Sep 11, 2019
1 parent c3cc896 commit f248e99
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
19 changes: 11 additions & 8 deletions pymatgen/analysis/path_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import scipy.stats
from scipy.interpolate import interp1d
import math
import logging

from abc import ABCMeta

Expand All @@ -29,6 +30,8 @@
__status__ = "Development"
__date__ = "March 17, 2015"

logger = logging.getLogger(__name__)


class NEBPathfinder:
def __init__(self, start_struct, end_struct, relax_sites, v, n_images=20):
Expand Down Expand Up @@ -61,7 +64,7 @@ def interpolate(self):
in relax_sites, the path is relaxed by the elastic band method within
the static potential V.
"""
images = self.__s1.interpolate(self.__s2, images=self.__n_images,
images = self.__s1.interpolate(self.__s2, nimages=self.__n_images,
interpolate_lattices=False)
for site_i in self.__relax_sites:
start_f = images[0].sites[site_i].frac_coords
Expand Down Expand Up @@ -145,7 +148,7 @@ def string_relax(start, end, V, n_images=25, dr=None, h=3.0, k=0.17,
# (http://www.cims.nyu.edu/~eve2/main.htm)
#

# print("Getting path from {} to {} (coords wrt V grid)".format(start, end))
# logger.debug("Getting path from {} to {} (coords wrt V grid)".format(start, end))

# Set parameters
if not dr:
Expand Down Expand Up @@ -195,7 +198,7 @@ def string_relax(start, end, V, n_images=25, dr=None, h=3.0, k=0.17,
dV[2][int(pt[0]) % d[0]][int(pt[1]) % d[1]][
int(pt[2]) % d[2]] / dr[0]] for pt in s])
# if(step % 100 == 0):
# print(edV)
# logger.debug(edV)

# Update according to force due to potential and string elasticity
ds_plus = s - np.roll(s, 1, axis=0)
Expand Down Expand Up @@ -229,11 +232,11 @@ def string_relax(start, end, V, n_images=25, dr=None, h=3.0, k=0.17,
"avoid divergence.")

if step > min_iter and tol < max_tol:
print("Converged at step {}".format(step))
logger.debug("Converged at step {}".format(step))
break

if step % 100 == 0:
print("Step {} - ds = {}".format(step, tol))
logger.debug("Step {} - ds = {}".format(step, tol))
return s

@staticmethod
Expand Down Expand Up @@ -299,8 +302,8 @@ def rescale_field(self, new_dim):
np.ndindex(v_dim[0] + 1, v_dim[1] + 1, v_dim[2] + 1))])
v_ogrid = padded_v.reshape(
((v_dim[0] + 1) * (v_dim[1] + 1) * (v_dim[2] + 1), -1))
ngrid_a, ngrid_b, ngrid_c = np.mgrid[0: v_dim[0]: v_dim[0] / new_dim[0], 0: v_dim[1]: v_dim[1] / new_dim[1],
0: v_dim[2]: v_dim[2] / new_dim[2]]
ngrid_a, ngrid_b, ngrid_c = (np.mgrid[0: v_dim[0]: v_dim[0] / new_dim[0], 0: v_dim[1]: v_dim[1] / new_dim[1],
0: v_dim[2]: v_dim[2] / new_dim[2]])

v_ngrid = scipy.interpolate.griddata(ogrid_list, v_ogrid,
(ngrid_a, ngrid_b, ngrid_c),
Expand Down Expand Up @@ -412,7 +415,7 @@ def __add_gaussians(s, dim, r=1.5):
[a_d / dim[0], b_d / dim[1], c_d / dim[2]])
d_f = sorted(s.get_sites_in_sphere(coords_f, s.lattice.a),
key=lambda x: x[1])[0][1]
# print(d_f)
# logger.debug(d_f)
gauss_dist[int(a_d)][int(b_d)][int(c_d)] = d_f / r
v = scipy.stats.norm.pdf(gauss_dist)
return v
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, mol):
obmol.ConnectTheDots()
obmol.PerceiveBondOrders()
obmol.SetTotalSpinMultiplicity(mol.spin_multiplicity)
obmol.SetTotalCharge(mol.charge)
obmol.SetTotalCharge(int(mol.charge))
obmol.Center()
obmol.Kekulize()
obmol.EndModify()
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def para_dict_to_string(para, joiner=" "):
output.append("")
output.append(self.title)
output.append("")
output.append("{} {}".format(self.charge, self.spin_multiplicity))
output.append("%d %d" % (self.charge, self.spin_multiplicity))
if isinstance(self._mol, Molecule):
if cart_coords is True:
output.append(self.get_cart_coords())
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/nwchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def __str__(self):
""")

output = t.substitute(
title=self.title, charge=self.charge,
title=self.title, charge=int(self.charge),
spinmult=self.spin_multiplicity,
basis_set_option=self.basis_set_option,
bset_spec="\n".join(bset_spec),
Expand Down
21 changes: 9 additions & 12 deletions pymatgen/io/tests/test_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
from pymatgen import Molecule
from pymatgen.io.gaussian import GaussianInput, GaussianOutput
from pymatgen.electronic_structure.core import Spin

"""
Created on Apr 17, 2012
"""


__author__ = "Shyue Ping Ong"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "0.1"
__maintainer__ = "Shyue Ping Ong"
__email__ = "shyuep@gmail.com"
__date__ = "Apr 17, 2012"



test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files', "molecules")

Expand Down Expand Up @@ -230,7 +228,7 @@ def test_props(self):
self.assertEqual(d["input"]["functional"], "hf")
self.assertAlmostEqual(d["output"]["final_energy"], -39.9768775602)
self.assertEqual(len(gau.cart_forces), 3)
self.assertEqual(gau.cart_forces[0][5], 0.009791094)
self.assertEqual(gau.cart_forces[0][5], 0.009791094)
self.assertEqual(gau.cart_forces[0][-1], -0.003263698)
self.assertEqual(gau.cart_forces[2][-1], -0.000000032)
self.assertEqual(gau.eigenvalues[Spin.up][-1], 1.95586)
Expand Down Expand Up @@ -262,7 +260,7 @@ def test_props(self):
self.assertEqual(h2o.frequencies[0][1]["symmetry"], "A'")
self.assertEqual(h2o.hessian[0, 0], 0.356872)
self.assertEqual(h2o.hessian.shape, (9, 9))
self.assertEqual(h2o.hessian[8, :].tolist(), [-0.143692e-01, 0.780136e-01,
self.assertEqual(h2o.hessian[8, :].tolist(), [-0.143692e-01, 0.780136e-01,
-0.362637e-01, -0.176193e-01,
0.277304e-01, -0.583237e-02,
0.319885e-01, -0.105744e+00,
Expand All @@ -273,12 +271,12 @@ def test_pop(self):
self.assertEqual(gau.num_basis_func, 13)
self.assertEqual(gau.electrons, (5, 5))
self.assertEqual(gau.is_spin, True)
self.assertListEqual(gau.eigenvalues[Spin.down], [-20.55343, -1.35264,
-0.72655, -0.54824,
-0.49831, 0.20705,
0.30297, 1.10569,
1.16144, 1.16717,
1.20460, 1.38903,
self.assertListEqual(gau.eigenvalues[Spin.down], [-20.55343, -1.35264,
-0.72655, -0.54824,
-0.49831, 0.20705,
0.30297, 1.10569,
1.16144, 1.16717,
1.20460, 1.38903,
1.67608])
mo = gau.molecular_orbital
self.assertEqual(len(mo), 2) # la 6
Expand Down Expand Up @@ -310,7 +308,6 @@ def test_pop(self):
self.assertEqual(gau.bond_orders[(0, 1)], 0.7582)
self.assertEqual(gau.bond_orders[(1, 2)], 0.0002)


def test_scan(self):
gau = GaussianOutput(os.path.join(test_dir, "so2_scan.log"))
d = gau.read_scan()
Expand Down

0 comments on commit f248e99

Please sign in to comment.