<commit_before>import os
from unittest import TestCase
from pymatgen import Molecule
from pymatgen.io.qchemio import QcInput

__author__ = 'xiaohuiqu'


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


coords = [[0.000000, 0.000000, 0.000000],
          [0.000000, 0.000000, 1.089000],
          [1.026719, 0.000000, -0.363000],
          [-0.513360, -0.889165, -0.363000],
          [-0.513360, 0.889165, -0.363000]]
mol = Molecule(["C", "H", "H", "H", "Cl"], coords)

coords2 = [[0.0, 0.0, -2.4],
          [0.0, 0.0, 0.0],
          [0.0, 0.0, 2.4]]
heavy_mol = Molecule(["Br", "Cd", "Br"], coords2)


class TestQcInput(TestCase):

    def elementary_io_verify(self, text, qcinp):
        self.to_and_from_dict_test(qcinp)
        self.from_string_test(contents=text, ref_dict=qcinp.to_dict)

    def to_and_from_dict_verify(self, qcinp):
        """
        Helper function. This function should be called in each specific test.
        """
        d1 = qcinp.to_dict
        qc2 = QcInput.from_dict(d1)
        d2 = qc2.to_dict
        self.assertEqual(d1, d2)

    def from_string_test(self, contents, ref_dict):
        qcinp = QcInput.from_string(contents)
        d2 = qcinp.to_dict
        self.assertEqual(ref_dict, d2)

    def test_read_zmatrix(self):
        contents = '''$moLEcule

 1 2

 S
 C  1 1.726563
 H  2 1.085845 1 119.580615
 C  2 1.423404 1 114.230851 3 -180.000000 0
 H  4 1.084884 2 122.286346 1 -180.000000 0
 C  4 1.381259 2 112.717365 1 0.000000 0
 H  6 1.084731 4 127.143779 2 -180.000000 0
 C  6 1.415867 4 110.076147 2 0.000000 0
 F  8 1.292591 6 124.884374 4 -180.000000 0
$end

$reM
   BASIS  =  6-31+G*
   EXCHANGE  =  B3LYP
   jobtype  =  freq
$end

'''
        qcinp = QcInput.from_string(contents)
        ans = '''$molecule
 1  2
 S           0.00000000        0.00000000        0.00000000
 C           0.00000000        0.00000000        1.72656300
 H          -0.94431813        0.00000000        2.26258784
 C           1.29800105       -0.00000002        2.31074808
 H           1.45002821       -0.00000002        3.38492732
 C           2.30733813       -0.00000003        1.36781908
 H           3.37622632       -0.00000005        1.55253338
 C           1.75466906       -0.00000003        0.06427152
 F           2.44231414       -0.00000004       -1.03023099
$end


$rem
   jobtype = freq
  exchange = b3lyp
     basis = 6-31+g*
$end

'''
        self.assertEqual(str(qcinp), ans)

    def test_no_mol(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 -1  2
 read
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
$end

'''
        qcinp = QcInput(molecule="READ", title="Test Methane",
                        exchange="B3LYP", jobtype="SP", charge=-1,
                        spin_multiplicity=2,
                        basis_set="6-31+G*")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_simple_basis_str(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_aux_basis_str(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
    jobtype = freq
   exchange = xygjos
      basis = gen
  aux_basis = gen
$end


$aux_basis
 C
 rimp2-cc-pvdz
 ****
 Cl
 rimp2-aug-cc-pvdz
 ****
 H
 rimp2-cc-pvdz
 ****
$end


$basis
 C
 6-31g*
 ****
 Cl
 6-31+g*
 ****
 H
 6-31g*
 ****
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="xygjos",
                        jobtype="Freq",
                        basis_set={"C": "6-31G*", "h": "6-31g*",
                                   "CL": "6-31+g*"},
                        aux_basis_set={"c": "rimp2-cc-pvdz",
                                       "H": "rimp2-cc-pvdz",
                                       "Cl": "rimp2-aug-cc-pvdz"})
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_ecp_str(self):
        ans = '''$comments
 Test ECP
$end


$molecule
 0  1
 Br          0.00000000        0.00000000       -2.40000000
 Cd          0.00000000        0.00000000        0.00000000
 Br          0.00000000        0.00000000        2.40000000
$end


$rem
   jobtype = opt
  exchange = b3lyp
     basis = gen
       ecp = gen
$end


$basis
 Br
 srlc
 ****
 Cd
 srsc
 ****
$end


$ecp
 Br
 srlc
 ****
 Cd
 srsc
 ****
$end

'''
        qcinp = QcInput(heavy_mol, title="Test ECP", exchange="B3LYP",
                        jobtype="Opt",
                        basis_set={"Br": "srlc", "Cd": "srsc"},
                        ecp={"Br": "SrlC", "Cd": "srsc"})
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_memory(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
     jobtype = sp
    exchange = b3lyp
       basis = 6-31+g*
  mem_static = 500
   mem_total = 18000
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_memory(total=18000, static=500)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_max_num_of_scratch_files(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
           jobtype = sp
          exchange = b3lyp
             basis = 6-31+g*
  max_sub_file_num = 500
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_max_num_of_scratch_files(500)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_max_scf_iterations(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
         jobtype = sp
        exchange = b3lyp
           basis = 6-31+g*
  max_scf_cycles = 100
   scf_algorithm = diis_gdm
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_scf_algorithm_and_iterations(algorithm="diis_gdm",
                                               iterations=100)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_scf_convergence_threshold(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
          jobtype = sp
         exchange = b3lyp
            basis = 6-31+g*
  scf_convergence = 8
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_scf_convergence_threshold(exponent=8)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_integral_threshold(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
    thresh = 14
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_integral_threshold(thresh=14)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_dft_grid(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
   xc_grid = 000110000590
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_dft_grid(radical_points=110, angular_points=590)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_scf_initial_guess(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
    jobtype = sp
   exchange = b3lyp
      basis = 6-31+g*
  scf_guess = gwh
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_scf_initial_guess("GWH")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_geom_opt_max_cycles(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 1  2
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
              jobtype = sp
             exchange = b3lyp
                basis = 6-31+g*
  geom_opt_max_cycles = 100
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP", charge=1, spin_multiplicity=2,
                        basis_set="6-31+G*")
        qcinp.set_geom_max_iterations(100)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_geom_opt_coords_type(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
          jobtype = sp
         exchange = b3lyp
            basis = 6-31+g*
  geom_opt_coords = 0
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_geom_opt_coords_type("cartesian")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_scale_geom_opt_threshold(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
                    jobtype = sp
                   exchange = b3lyp
                      basis = 6-31+g*
  geom_opt_tol_displacement = 120
        geom_opt_tol_energy = 10
      geom_opt_tol_gradient = 30
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.scale_geom_opt_threshold(gradient=0.1, displacement=0.1,
                                       energy=0.1)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_geom_opt_use_gdiis(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
            jobtype = sp
           exchange = b3lyp
              basis = 6-31+g*
  geom_opt_max_diis = -1
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_geom_opt_use_gdiis()
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_disable_symmetry(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
     jobtype = sp
    exchange = b3lyp
       basis = 6-31+g*
  sym_ignore = True
    symmetry = False
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.disable_symmetry()
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_use_cosmo(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
             jobtype = sp
            exchange = b3lyp
               basis = 6-31+g*
  solvent_dielectric = 35.0
      solvent_method = cosmo
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.use_cosmo(dielectric_constant=35.0)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)<commit_msg>only compare text for z-matrix test<commit_after>import os
from unittest import TestCase
from pymatgen import Molecule
from pymatgen.io.qchemio import QcInput

__author__ = 'xiaohuiqu'


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


coords = [[0.000000, 0.000000, 0.000000],
          [0.000000, 0.000000, 1.089000],
          [1.026719, 0.000000, -0.363000],
          [-0.513360, -0.889165, -0.363000],
          [-0.513360, 0.889165, -0.363000]]
mol = Molecule(["C", "H", "H", "H", "Cl"], coords)

coords2 = [[0.0, 0.0, -2.4],
          [0.0, 0.0, 0.0],
          [0.0, 0.0, 2.4]]
heavy_mol = Molecule(["Br", "Cd", "Br"], coords2)


class TestQcInput(TestCase):

    def elementary_io_test(self, text, qcinp):
        self.to_and_from_dict_test(qcinp)
        self.from_string_test(contents=text, ref_dict=qcinp.to_dict)

    def to_and_from_dict_test(self, qcinp):
        """
        Helper function. This function should be called in each specific test.
        """
        d1 = qcinp.to_dict
        qc2 = QcInput.from_dict(d1)
        d2 = qc2.to_dict
        self.assertEqual(d1, d2)

    def from_string_test(self, contents, ref_dict):
        qcinp = QcInput.from_string(contents)
        d2 = qcinp.to_dict
        self.assertEqual(ref_dict, d2)

    def test_read_zmatrix(self):
        contents = '''$moLEcule

 1 2

 S
 C  1 1.726563
 H  2 1.085845 1 119.580615
 C  2 1.423404 1 114.230851 3 -180.000000 0
 H  4 1.084884 2 122.286346 1 -180.000000 0
 C  4 1.381259 2 112.717365 1 0.000000 0
 H  6 1.084731 4 127.143779 2 -180.000000 0
 C  6 1.415867 4 110.076147 2 0.000000 0
 F  8 1.292591 6 124.884374 4 -180.000000 0
$end

$reM
   BASIS  =  6-31+G*
   EXCHANGE  =  B3LYP
   jobtype  =  freq
$end

'''
        qcinp = QcInput.from_string(contents)
        ans = '''$molecule
 1  2
 S           0.00000000        0.00000000        0.00000000
 C           0.00000000        0.00000000        1.72656300
 H          -0.94431813        0.00000000        2.26258784
 C           1.29800105       -0.00000002        2.31074808
 H           1.45002821       -0.00000002        3.38492732
 C           2.30733813       -0.00000003        1.36781908
 H           3.37622632       -0.00000005        1.55253338
 C           1.75466906       -0.00000003        0.06427152
 F           2.44231414       -0.00000004       -1.03023099
$end


$rem
   jobtype = freq
  exchange = b3lyp
     basis = 6-31+g*
$end

'''
        ans_tokens = ans.split('\n')
        ans_text_part = ans_tokens[:2] + ans_tokens[11:]
        converted_tokens = str(qcinp).split('\n')
        converted_text_pat = converted_tokens[:2] + converted_tokens[11:]
        self.assertEqual(str(qcinp), ans)

    def test_no_mol(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 -1  2
 read
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
$end

'''
        qcinp = QcInput(molecule="READ", title="Test Methane",
                        exchange="B3LYP", jobtype="SP", charge=-1,
                        spin_multiplicity=2,
                        basis_set="6-31+G*")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_simple_basis_str(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_aux_basis_str(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
    jobtype = freq
   exchange = xygjos
      basis = gen
  aux_basis = gen
$end


$aux_basis
 C
 rimp2-cc-pvdz
 ****
 Cl
 rimp2-aug-cc-pvdz
 ****
 H
 rimp2-cc-pvdz
 ****
$end


$basis
 C
 6-31g*
 ****
 Cl
 6-31+g*
 ****
 H
 6-31g*
 ****
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="xygjos",
                        jobtype="Freq",
                        basis_set={"C": "6-31G*", "h": "6-31g*",
                                   "CL": "6-31+g*"},
                        aux_basis_set={"c": "rimp2-cc-pvdz",
                                       "H": "rimp2-cc-pvdz",
                                       "Cl": "rimp2-aug-cc-pvdz"})
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_ecp_str(self):
        ans = '''$comments
 Test ECP
$end


$molecule
 0  1
 Br          0.00000000        0.00000000       -2.40000000
 Cd          0.00000000        0.00000000        0.00000000
 Br          0.00000000        0.00000000        2.40000000
$end


$rem
   jobtype = opt
  exchange = b3lyp
     basis = gen
       ecp = gen
$end


$basis
 Br
 srlc
 ****
 Cd
 srsc
 ****
$end


$ecp
 Br
 srlc
 ****
 Cd
 srsc
 ****
$end

'''
        qcinp = QcInput(heavy_mol, title="Test ECP", exchange="B3LYP",
                        jobtype="Opt",
                        basis_set={"Br": "srlc", "Cd": "srsc"},
                        ecp={"Br": "SrlC", "Cd": "srsc"})
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_memory(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
     jobtype = sp
    exchange = b3lyp
       basis = 6-31+g*
  mem_static = 500
   mem_total = 18000
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_memory(total=18000, static=500)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_max_num_of_scratch_files(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
           jobtype = sp
          exchange = b3lyp
             basis = 6-31+g*
  max_sub_file_num = 500
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_max_num_of_scratch_files(500)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_max_scf_iterations(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
         jobtype = sp
        exchange = b3lyp
           basis = 6-31+g*
  max_scf_cycles = 100
   scf_algorithm = diis_gdm
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_scf_algorithm_and_iterations(algorithm="diis_gdm",
                                               iterations=100)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_scf_convergence_threshold(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
          jobtype = sp
         exchange = b3lyp
            basis = 6-31+g*
  scf_convergence = 8
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_scf_convergence_threshold(exponent=8)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_integral_threshold(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
    thresh = 14
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_integral_threshold(thresh=14)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_dft_grid(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
   jobtype = sp
  exchange = b3lyp
     basis = 6-31+g*
   xc_grid = 000110000590
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_dft_grid(radical_points=110, angular_points=590)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_scf_initial_guess(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
    jobtype = sp
   exchange = b3lyp
      basis = 6-31+g*
  scf_guess = gwh
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_scf_initial_guess("GWH")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_geom_opt_max_cycles(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 1  2
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
              jobtype = sp
             exchange = b3lyp
                basis = 6-31+g*
  geom_opt_max_cycles = 100
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP", charge=1, spin_multiplicity=2,
                        basis_set="6-31+G*")
        qcinp.set_geom_max_iterations(100)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_geom_opt_coords_type(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
          jobtype = sp
         exchange = b3lyp
            basis = 6-31+g*
  geom_opt_coords = 0
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_geom_opt_coords_type("cartesian")
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_scale_geom_opt_threshold(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
                    jobtype = sp
                   exchange = b3lyp
                      basis = 6-31+g*
  geom_opt_tol_displacement = 120
        geom_opt_tol_energy = 10
      geom_opt_tol_gradient = 30
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.scale_geom_opt_threshold(gradient=0.1, displacement=0.1,
                                       energy=0.1)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_set_geom_opt_use_gdiis(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
            jobtype = sp
           exchange = b3lyp
              basis = 6-31+g*
  geom_opt_max_diis = -1
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.set_geom_opt_use_gdiis()
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_disable_symmetry(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
     jobtype = sp
    exchange = b3lyp
       basis = 6-31+g*
  sym_ignore = True
    symmetry = False
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.disable_symmetry()
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)

    def test_use_cosmo(self):
        ans = '''$comments
 Test Methane
$end


$molecule
 0  1
 C           0.00000000        0.00000000        0.00000000
 H           0.00000000        0.00000000        1.08900000
 H           1.02671900        0.00000000       -0.36300000
 H          -0.51336000       -0.88916500       -0.36300000
 Cl         -0.51336000        0.88916500       -0.36300000
$end


$rem
             jobtype = sp
            exchange = b3lyp
               basis = 6-31+g*
  solvent_dielectric = 35.0
      solvent_method = cosmo
$end

'''
        qcinp = QcInput(mol, title="Test Methane", exchange="B3LYP",
                        jobtype="SP",
                        basis_set="6-31+G*")
        qcinp.use_cosmo(dielectric_constant=35.0)
        self.assertEqual(str(qcinp), ans)
        self.elementary_io_test(ans, qcinp)
{'fraction_non_alphanumeric': 0.10796953705924682, 'fraction_numerical': 0.17732070040777165, 'mean_word_length': 1.4814373930511122, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 222, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4102650', 'n_tokens_mistral': 15742, 'n_tokens_neox': 11520, 'n_words': 2328}