Beispiel #1
0
    def test_excited_supersystem(self):
        mol = gto.Mole()
        mol.verbose = 3
        mol.atom = '''
        H 0. -2.757 2.857
        H 0. 2.757 2.857
        '''
        mol.basis = '3-21g'
        mol.build()
        env_method = 'm06'
        hl_method = 'ccsd'
        subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method)

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        He 1.0 20.0 0.0
        He 3.0 20.0 0.0'''
        mol2.basis = '3-21g'
        mol2.build()
        env_method = 'm06'
        subsys2 = cluster_subsystem.ClusterEnvSubSystem(mol2, env_method)

        mol12 = helpers.concat_mols([mol, mol2])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'm06')

        supersystem = cluster_supersystem.ClusterSuperSystem([subsys, subsys2], 'm06', fs_scf_obj, init_guess='minao',
                fs_excited=True, fs_excited_dict={'nroots':4}, ft_excited_relax=True, ft_excited_dict={'nroots':2})

        self.assertTrue(supersystem.fs_excited)
        self.assertTrue(supersystem.ft_excited_relax)
        self.assertDictEqual(supersystem.fs_excited_dict, {'nroots':4})
        self.assertDictEqual(supersystem.ft_excited_dict, {'nroots':2})
        self.assertEqual(supersystem.fs_excited_nroots, 4)
        self.assertEqual(supersystem.ft_excited_nroots, 2)
def combine_subsystems(subsystems, env_method, fs_kwargs=None):
    """Combines multiple subsystems into one larger subsystem object.

    Parameters
    __________
    subsystems : array
        A list of subsystem objects to combine
    env_method : str
        The name of the environment method to use for the combined subsystem
    fs_kwargs : dict
        Settings for the full system. Determines if subsystem is unrestricted
        (default is None)

    Returns
    -------
    ClusterEnvSubSystem
        The combined subsystem object.
    """
    mol_list = [x.mol for x in subsystems]
    mol = helpers.concat_mols(mol_list)
    sub_order = subsystems[0].env_order
    sub_unrestricted = False
    if fs_kwargs is not None:
        if 'fs_unrestricted' in fs_kwargs.keys():
            sub_unrestricted = fs_kwargs['fs_unrestricted']
    #Need a way of specifying the settings of the implied subsystem somehow.
    return cluster_subsystem.ClusterEnvSubSystem(mol,
                                                 env_method,
                                                 env_order=sub_order,
                                                 unrestricted=sub_unrestricted)
Beispiel #3
0
    def test_basic_interaction_mediator(self):
        subsystems = [self.sub2, self.sub3]
        mediator = interaction_mediator.InteractionMediator(subsystems)
        self.assertEqual(len(mediator.supersystems), 1)

        mol12 = helpers.concat_mols([self.sub2.mol, self.sub3.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'm06')
        supersystem_1 = cluster_supersystem.ClusterSuperSystem(subsystems, 'm06', fs_scf_obj) 
        for i in range(len(mediator.supersystems)):
            test = mediator.supersystems[i]
            self.assertEqual(test.env_method, supersystem_1.env_method)
            self.assertEqual(test.proj_oper, supersystem_1.proj_oper)
            self.assertEqual(test.max_cycle, supersystem_1.max_cycle)
            self.assertEqual(test.conv_tol, supersystem_1.conv_tol)
            self.assertEqual(test.damp, supersystem_1.damp)
            self.assertEqual(test.init_guess, supersystem_1.init_guess)
            self.assertEqual(test.fock_subcycles, supersystem_1.fock_subcycles)

            test_fs_scf = test.fs_scf_obj
            sup_fs_scf = supersystem_1.fs_scf_obj
            self.assertEqual(test_fs_scf.max_cycle, sup_fs_scf.max_cycle)
            self.assertEqual(test_fs_scf.conv_tol, sup_fs_scf.conv_tol)
            self.assertEqual(test_fs_scf.damp, sup_fs_scf.damp)
            self.assertEqual(test_fs_scf.level_shift_factor, sup_fs_scf.level_shift_factor)
            self.assertEqual(test_fs_scf.init_guess, sup_fs_scf.init_guess)
            self.assertEqual(test_fs_scf.grids.level, sup_fs_scf.grids.level)
            self.assertEqual(test_fs_scf.small_rho_cutoff, sup_fs_scf.small_rho_cutoff)
Beispiel #4
0
    def test_hsros_supersystem(self):
        mol = gto.Mole()
        mol.verbose = 3
        mol.atom = '''
        H 0. -2.757 2.857
        H 0. 2.757 2.857
        '''
        mol.basis = '3-21g'
        mol.spin = 2
        mol.build()
        env_method = 'm06'
        hl_method = 'ccsd'
        subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method)

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        He 1.0 20.0 0.0
        He 3.0 20.0 0.0'''
        mol2.basis = '3-21g'
        mol2.build()

        env_method = 'm06'
        subsys2 = cluster_subsystem.ClusterEnvSubSystem(mol2, env_method)
        mol12 = helpers.concat_mols([mol, mol2])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'm06')
        supersystem = cluster_supersystem.ClusterSuperSystem([subsys, subsys2], 'm06', fs_scf_obj, init_guess='minao')

        #Check SCF object
        scf_obj = supersystem.fs_scf_obj
        comp_scf_obj = dft.ROKS(gto.mole.conc_mol(mol, mol2))
        self.assertEqual(type(scf_obj), type(comp_scf_obj))
        self.assertEqual(scf_obj.xc, 'm06')
Beispiel #5
0
    def test_partialghost_supersystem(self):
        mol = gto.Mole()
        mol.verbose = 3
        mol.atom = '''
        H 0. -2.757 2.857
        H 0. 2.757 2.857
        ghost:H 0. 0. 2.857
        '''
        mol.basis = '3-21g'
        mol.build()
        env_method = 'm06'
        hl_method = 'ccsd'
        subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method)

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        He 1.0 20.0 0.0
        He 3.0 20.0 0.0'''
        mol2.basis = '3-21g'
        mol2.build()
        env_method = 'm06'
        subsys2 = cluster_subsystem.ClusterEnvSubSystem(mol2, env_method)

        mol12 = helpers.concat_mols([mol, mol2])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'b3lyp')

        supersystem = cluster_supersystem.ClusterSuperSystem([subsys, subsys2], 'b3lyp', fs_scf_obj, init_guess='minao')
        self.assertEqual(supersystem.env_method, 'b3lyp')
        self.assertEqual(supersystem.proj_oper, 'huz')
        self.assertEqual(supersystem.init_guess, 'minao')
Beispiel #6
0
    def test_density_fitting_supersystem(self):
        mol = gto.Mole()
        mol.verbose = 3
        mol.atom = '''
        H 0. -2.757 2.857
        H 0. 2.757 2.857
        '''
        mol.basis = '3-21g'
        mol.build()
        env_method = 'm06'
        hl_method = 'ccsd'
        subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method)

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        He 1.0 20.0 0.0
        He 3.0 20.0 0.0'''
        mol2.basis = '3-21g'
        mol2.build()

        env_method = 'm06'
        subsys2 = cluster_subsystem.ClusterEnvSubSystem(mol2, env_method)
        mol12 = helpers.concat_mols([mol, mol2])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'm06', density_fitting=True)
        supersystem = cluster_supersystem.ClusterSuperSystem([subsys, subsys2], 'm06', fs_scf_obj, init_guess='minao')

        #Check SCF object
        scf_obj = supersystem.fs_scf_obj
        from pyscf.df.df_jk import _DFHF
        self.assertTrue(isinstance(scf_obj, _DFHF))
        self.assertEqual(scf_obj.xc, 'm06')
        self.assertEqual(scf_obj.density_fitting, True)
Beispiel #7
0
    def test_remove_ovlp(self):
        test_mol_16 = helpers.concat_mols([self.mol1, self.mol6])

        corr_mol16 = gto.M()
        corr_mol16.atom = """
        H-0   -1.06  0.0   0.0
        C-0   0.0   0.0   0.0
        C-1   1.2   0.0   0.0
        H-1   2.26  0.0   0.0
        """
        corr_mol16.basis = {
            'C-0': 'sto-3g',
            'H-0': 'sto-3g',
            'C-1': '6-311g',
            'H-1': '6-311g'
        }

        with self.assertRaises(AssertionError):
            test_mol_166 = helpers.concat_mols([test_mol_16, self.mol6])

        test_mol_378 = helpers.concat_mols([self.mol3, self.mol7, self.mol8])
        corr_mol378 = gto.M()
        corr_mol378.atom = """
        O-0   -1.16   0.0   0.0
        GHOST-C-1 2.0 0.0 0.0
        O-1    0.0   1.16   0.0
        C-2    0.0   0.0   0.0
        """
        corr_mol378.basis = {
            'O-0': 'sto-3g',
            'O-1': 'cc-pVTZ',
            'GHOST-C-1': 'aug-cc-pVDZ',
            'C-2': 'cc-pVDZ'
        }
        corr_mol378.build()
        self.assertTrue(gto.same_basis_set(test_mol_378, corr_mol378))
        self.assertTrue(gto.same_mol(test_mol_378, corr_mol378))
Beispiel #8
0
    def test_basic(self):
        test_mol_12 = helpers.concat_mols([self.mol1, self.mol2])

        corr_mol12 = gto.M()
        corr_mol12.atom = """
        H-0   -1.06  0.0   0.0
        C-0   0.0   0.0   0.0
        C-1   1.2   0.0   0.0
        H-1   2.26  0.0   0.0
        """
        corr_mol12.spin = 0
        corr_mol12.basis = {
            'C-0': 'sto-3g',
            'H-0': 'sto-3g',
            'C-1': '6-311g',
            'H-1': '6-311g'
        }
        corr_mol12.build()

        self.assertEqual(test_mol_12.spin, corr_mol12.spin)
        self.assertTrue(gto.same_mol(test_mol_12, corr_mol12))
        self.assertTrue(gto.same_mol(test_mol_12, corr_mol12))

        test_mol_345 = helpers.concat_mols([self.mol3, self.mol4, self.mol5])

        corr_mol345 = gto.M()
        corr_mol345.atom = """
        O-0   -1.16   0.0   0.0
        C-1   0.0   0.0   0.0
        O-2   1.16   0.0   0.0
        """
        corr_mol345.basis = {'O-0': 'sto-3g', 'C-1': '6-311g', 'O-2': 'sto-3g'}
        corr_mol345.build()

        self.assertTrue(gto.same_basis_set(test_mol_345, corr_mol345))
        self.assertTrue(gto.same_mol(test_mol_345, corr_mol345))
Beispiel #9
0
    def test_basic_supersystem(self):
        mol = gto.Mole()
        mol.verbose = 3
        mol.atom = '''
        H 0. -2.757 2.857
        H 0. 2.757 2.857
        '''
        mol.basis = '3-21g'
        mol.build()
        env_method = 'm06'
        hl_method = 'ccsd'
        subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method)

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        He 1.0 20.0 0.0
        He 3.0 20.0 0.0'''
        mol2.basis = '3-21g'
        mol2.build()
        env_method = 'm06'
        subsys2 = cluster_subsystem.ClusterEnvSubSystem(mol2, env_method)

        mol12 = helpers.concat_mols([mol, mol2])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'm06')

        supersystem = cluster_supersystem.ClusterSuperSystem([subsys, subsys2], 'm06', fs_scf_obj, init_guess='minao')
        self.assertEqual(supersystem.env_method, 'm06')
        self.assertEqual(supersystem.proj_oper, 'huz')
        self.assertEqual(supersystem.max_cycle, 200)
        self.assertEqual(supersystem.conv_tol, 1e-9)
        self.assertEqual(supersystem.damp, 0)
        self.assertEqual(supersystem.init_guess, 'minao')
        self.assertEqual(supersystem.fock_subcycles, 1)

        #Check SCF object
        scf_obj = supersystem.fs_scf_obj
        comp_scf_obj = dft.RKS(gto.mole.conc_mol(mol, mol2))
        self.assertEqual(type(scf_obj), type(comp_scf_obj))
        print (comp_scf_obj.mol._basis)
        print (supersystem.mol._basis)
        self.assertTrue(gto.same_mol(comp_scf_obj.mol, supersystem.mol, cmp_basis=False))
        self.assertEqual(scf_obj.xc, 'm06')
Beispiel #10
0
    def test_simple_subsystems(self):
        sub1 = ClusterHLSubSystem(self.mol1, 'lda', 'rhf')
        sub2 = ClusterEnvSubSystem(self.mol2, 'lda')
        subsystems = [sub1, sub2]
        mediator = InteractionMediator(subsystems)
        mediator.do_embedding()

        #True Values
        sub1 = ClusterHLSubSystem(self.mol1, 'lda', 'rhf')
        sub2 = ClusterEnvSubSystem(self.mol2, 'lda')
        subsystems = [sub1, sub2]
        mol12 = helpers.concat_mols([sub1.mol, sub2.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'lda')
        supersystem = ClusterSuperSystem(subsystems, 'lda', fs_scf_obj)
        supersystem.init_density()
        sup_e = supersystem.get_supersystem_energy()
        supersystem.freeze_and_thaw()
        self.assertTrue(
            np.allclose(supersystem.get_emb_dmat(),
                        mediator.supersystems[0].get_emb_dmat()))
        self.assertTrue(
            np.allclose(supersystem.fs_dmat, mediator.supersystems[0].fs_dmat))
Beispiel #11
0
    def test_simple_subsystems(self):
        sub1 = ClusterHLSubSystem(self.mol1, 'lda', 'rhf')
        sub2 = ClusterEnvSubSystem(self.mol2, 'lda')
        subsystems = [sub1, sub2]
        mediator = InteractionMediator(subsystems)
        mediator.do_embedding()
        test_emb_energy = mediator.get_emb_energy()

        #True Values
        sub1 = ClusterHLSubSystem(self.mol1, 'lda', 'rhf')
        sub2 = ClusterEnvSubSystem(self.mol2, 'lda')
        subsystems = [sub1, sub2]
        mol12 = helpers.concat_mols([sub1.mol, sub2.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'lda')
        supersystem = ClusterSuperSystem(subsystems, 'lda', fs_scf_obj)
        supersystem.init_density()
        sup_e = supersystem.get_supersystem_energy()
        supersystem.freeze_and_thaw()
        supersystem.get_env_energy()
        supersystem.get_hl_energy()
        env_e = supersystem.subsystems[0].env_energy
        hl_e = supersystem.subsystems[0].hl_energy
        true_emb_energy = sup_e - env_e + hl_e
        self.assertAlmostEqual(true_emb_energy, test_emb_energy, delta=1e-9)
def gen_supersystems(sup_kwargs, subsystems, filename, scrdir):
    """Generates the list of supersystems made from all subsystems.

    Parameters
    __________
    sup_kwargs : array
        An array of supersystem kwarg dictionaries.
    subsystems : array
        An array of subsystem objects.
    filename : str
        The name of the input file.
    scrdir : str
        The path to the scratch directory

    Returns
    _______
    Array
        A list of supersystem objects.
    """
    supersystems = []
    sorted_subs = sorted(subsystems, key=lambda x: x.env_order)
    while len(sorted_subs) > 0:
        curr_order = sorted_subs[0].env_order
        curr_method = sorted_subs[0].env_method
        curr_sup_kwargs = {}
        sub_sup_kwargs = {}
        if sup_kwargs is not None:
            match_sup_kwargs = [
                x for x in sup_kwargs if x['env_order'] == curr_order
            ]
            sub_sup_kwargs = [
                x for x in sup_kwargs if x['env_order'] == (curr_order + 1)
            ]
            assert len(match_sup_kwargs) < 2, 'Ambigious supersystem settings'
            curr_sup_kwargs = match_sup_kwargs[0]
        higher_order_subs = [
            x for x in sorted_subs if x.env_order > curr_order
        ]
        sub_list = []
        while len(sorted_subs) > 0 and sorted_subs[0].env_order == curr_order:
            sub_list.append(sorted_subs.pop(0))
        if len(higher_order_subs) > 0:
            if len(sub_sup_kwargs) > 0:
                combined_subs = combine_subsystems(higher_order_subs,
                                                   curr_method,
                                                   fs_kwargs=sub_sup_kwargs[0])
            else:
                combined_subs = combine_subsystems(higher_order_subs,
                                                   curr_method)

            sub_list.append(combined_subs)
        mol_list = [x.mol for x in sub_list]
        full_mol = helpers.concat_mols(mol_list)
        fs_env_settings = curr_sup_kwargs.pop('fs_env_settings', None)
        if fs_env_settings:
            env_method = fs_env_settings.pop('env_method', None)
            if not env_method:
                env_method = sub_list[0].env_method
            fs_scf_obj = helpers.gen_scf_obj(full_mol, env_method,
                                             **fs_env_settings)
        else:
            env_method = sub_list[0].env_method
            fs_scf_obj = helpers.gen_scf_obj(full_mol, env_method)
        embed_dict = curr_sup_kwargs.get('embed_settings', None)
        if embed_dict:
            embed_dict['filename'] = filename
            supersystem = cluster_supersystem.ClusterSuperSystem(
                sub_list,
                env_method,
                fs_scf_obj,
                env_order=curr_order,
                **embed_dict)
        else:
            supersystem = cluster_supersystem.ClusterSuperSystem(
                sub_list,
                env_method,
                fs_scf_obj,
                env_order=curr_order,
                filename=filename)
        supersystems.append(supersystem)

    return supersystems
Beispiel #13
0
    def test_custom_supersystem(self):
        t_file = tempfile.NamedTemporaryFile()
        mol = gto.Mole()
        mol.verbose = 3
        mol.atom = '''
        O 0.0 0.0 0.0
        H 0. -2.757 2.857
        H 0. 2.757 2.857'''
        mol.basis = 'aug-cc-pVDZ'
        mol.build()
        env_method = 'm06'
        hl_method = 'ccsd'
        hl_dict = {'froz_orbs': 10}
        subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method, filename=t_file.name, hl_dict=hl_dict)

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        O 1.0 0.0 0.0
        O 3.0 0.0 0.0'''
        mol2.basis = 'aug-cc-pVDZ'
        mol2.verbose = 1
        mol2.build()
        env_method = 'm06'
        subsys2 = cluster_subsystem.ClusterEnvSubSystem(mol2, env_method, filename=t_file.name)

        mol12 = helpers.concat_mols([mol, mol2])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'b3lyp', max_cycle=3, conv_tol=2,
                                         damp=1, level_shift_factor=2.1,
                                         init_guess='atom', grid_level=2, 
                                         small_rho_cutoff=1e-2, save_orbs=True,
                                         save_density=True,
                                         stability_analysis='internal')

        supersystem = cluster_supersystem.ClusterSuperSystem([subsys, subsys2],
                          'b3lyp', fs_scf_obj, proj_oper='huzfermi', max_cycle=2, 
                          conv_tol=1e-1, diis_num=3, init_guess='1e', 
                          fock_subcycles=1, set_fermi=-0.1, damp=0.5, 
                          compare_density=True, save_density=True,
                          save_orbs=True, filename=t_file.name)

        self.assertEqual(supersystem.env_method, 'b3lyp')
        self.assertEqual(supersystem.proj_oper, 'huzfermi')
        self.assertEqual(supersystem.filename, t_file.name)
        self.assertEqual(supersystem.max_cycle, 2)
        self.assertEqual(supersystem.conv_tol, 1e-1)
        self.assertEqual(supersystem.damp, 0.5)
        self.assertIsInstance(supersystem.emb_diis, lib.diis.DIIS)
        self.assertIsInstance(supersystem.emb_diis_2, lib.diis.DIIS)
        self.assertEqual(supersystem.set_fermi, -0.1)
        self.assertEqual(supersystem.init_guess, '1e')
        self.assertEqual(supersystem.fock_subcycles, 1)
        self.assertEqual(supersystem.compare_density, True)
        self.assertEqual(supersystem.save_orbs, True)
        self.assertEqual(supersystem.save_density, True)

        fs_scf_obj = supersystem.fs_scf_obj
        self.assertEqual(fs_scf_obj.max_cycle, 3)
        self.assertEqual(fs_scf_obj.conv_tol, 2)
        self.assertEqual(fs_scf_obj.damp, 1)
        self.assertEqual(fs_scf_obj.level_shift_factor, 2.1)
        self.assertEqual(fs_scf_obj.init_guess, 'atom')
        self.assertEqual(fs_scf_obj.grids.level, 2)
        self.assertEqual(fs_scf_obj.small_rho_cutoff, 1e-2)
        self.assertEqual(fs_scf_obj.verbose, 1)
        self.assertEqual(fs_scf_obj.stability_analysis, 'internal')
        self.assertEqual(fs_scf_obj.save_orbs, True)
        self.assertEqual(fs_scf_obj.save_density, True)
Beispiel #14
0
    def test_density_multiple_subsystems(self):

        mol1 = gto.Mole()
        mol1.verbose = 3
        mol1.atom = '''
        H 0.758602  0.000000  0.504284
        H 0.758602  0.000000  -0.504284 
        O 0.0 0.0 0.0'''
        mol1.basis = '3-21g'
        mol1.build()

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        H 0.758602  2.000000  0.504284
        H 0.758602  2.000000  -0.504284 
        O 0.0 2.0 0.0'''
        mol2.basis = '3-21g'
        mol2.build()

        mol3 = gto.Mole()
        mol3.verbose = 3
        mol3.atom = '''
        H 0.758602  4.000000  0.504284
        H 0.758602  4.000000  -0.504284 
        O 0.0 4.0 0.0'''
        mol3.basis = '6-31g'
        mol3.build()

        mol4 = gto.Mole()
        mol4.verbose = 3
        mol4.atom = '''
        H 0.758602  6.000000  0.504284
        H 0.758602  6.000000  -0.504284 
        O 0.0 6.0 0.0'''
        mol4.basis = 'cc-pVDZ'
        mol4.build()

        mol5 = gto.Mole()
        mol5.verbose = 3
        mol5.atom = '''
        H 0.758602  8.000000  0.504284
        H 0.758602  8.000000  -0.504284 
        O 0.0 8.0 0.0'''
        mol5.basis = '3-21g'
        mol5.build()

        sub1 = ClusterEnvSubSystem(mol1, 'lda', env_order=1)
        sub2 = ClusterEnvSubSystem(mol2, 'lda', env_order=1)
        sub3 = ClusterEnvSubSystem(mol3, 'pbe', env_order=2)
        sub4 = ClusterEnvSubSystem(mol4, 'm06', env_order=3)
        sub5 = ClusterHLSubSystem(mol5, 'm06', 'rhf', env_order=3)
        subsystems = [sub1, sub2, sub3, sub4, sub5]

        sup1_alt_sub_mol = gto.Mole()
        sup1_alt_sub_mol.verbose = 3
        sup1_alt_sub_mol.atom = '''
        H-0 0.758602  4.000000  0.504284
        H-0 0.758602  4.000000  -0.504284 
        O-0 0.0 4.0 0.0
        H-1 0.758602  6.000000  0.504284
        H-1 0.758602  6.000000  -0.504284 
        O-1 0.0 6.0 0.0
        H-2 0.758602  8.000000  0.504284
        H-2 0.758602  8.000000  -0.504284 
        O-2 0.0 8.0 0.0'''
        sup1_alt_sub_mol.basis = {
            'O-0': '6-31g',
            'H-0': '6-31g',
            'O-1': 'cc-pVDZ',
            'H-1': 'cc-pVDZ',
            'O-2': '3-21g',
            'H-2': '3-21g'
        }
        sup1_alt_sub_mol.build()
        sup1_alt_sub = ClusterEnvSubSystem(sup1_alt_sub_mol,
                                           'pbe',
                                           env_order=2)
        mol123 = helpers.concat_mols([sub1.mol, sub2.mol, sup1_alt_sub.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol123, 'lda')
        supersystem_1 = ClusterSuperSystem([sub1, sub2, sup1_alt_sub], 'lda',
                                           fs_scf_obj)
        supersystem_1.init_density()

        sup2_alt_sub_mol = gto.Mole()
        sup2_alt_sub_mol.verbose = 3
        sup2_alt_sub_mol.atom = '''
        H-0 0.758602  6.000000  0.504284
        H-0 0.758602  6.000000  -0.504284 
        O-0 0.0 6.0 0.0
        H-1 0.758602  8.000000  0.504284
        H-1 0.758602  8.000000  -0.504284 
        O-1 0.0 8.0 0.0'''
        sup2_alt_sub_mol.basis = {
            'O-0': 'cc-pVDZ',
            'H-0': 'cc-pVDZ',
            'O-1': '3-21g',
            'H-1': '3-21g'
        }
        sup2_alt_sub_mol.build()

        sup2_alt_sub = ClusterEnvSubSystem(sup2_alt_sub_mol,
                                           'm06',
                                           env_order=3)
        mol123 = helpers.concat_mols([sub3.mol, sup2_alt_sub.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol123, 'pbe')
        supersystem_2 = ClusterSuperSystem([sub3, sup2_alt_sub],
                                           'pbe',
                                           fs_scf_obj,
                                           env_order=2)
        supersystem_2.init_density()
        mol123 = helpers.concat_mols([sub4.mol, sub5.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol123, 'm06')
        supersystem_3 = ClusterSuperSystem([sub4, sub5],
                                           'm06',
                                           fs_scf_obj,
                                           env_order=3)
        supersystem_3.init_density()
        supersystem_list = [supersystem_1, supersystem_2, supersystem_3]
        mediator = InteractionMediator(subsystems)
        #Ensure the densities are the same and the methods are correct should be enough.
        self.assertEqual(len(mediator.supersystems), 3)
        for i in range(len(mediator.supersystems)):
            test = mediator.supersystems[i]
            self.assertEqual(test.env_method, supersystem_list[i].env_method)
Beispiel #15
0
    def test_explicit_subsystems(self):
        #Use the fs settings for the smaller system for the subsystem settings.
        mol1 = gto.Mole()
        mol1.verbose = 3
        mol1.atom = '''
        O 0.0 0.0 0.0
        H 0. -2.757 2.857
        H 0. 2.757 2.857'''
        mol1.basis = 'sto-3g'
        mol1.build()

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        O 1.0 0.0 0.0
        H 1. -2.757 2.857
        H 1. 2.757 2.857'''
        mol2.basis = '3-21g'
        mol2.build()

        mol3 = gto.Mole()
        mol3.verbose = 3
        mol3.atom = '''
        O 2.0 0.0 0.0
        H 2. -2.757 2.857
        H 2. 2.757 2.857'''
        mol3.basis = '6-31g'
        mol3.build()

        mol4 = gto.Mole()
        mol4.verbose = 3
        mol4.atom = '''
        O 3.0 0.0 0.0
        H 3. -2.757 2.857
        H 3. 2.757 2.857'''
        mol4.basis = 'aug-cc-pVTZ'
        mol4.build()

        mol5 = gto.Mole()
        mol5.verbose = 3
        mol5.atom = '''
        O 4.0 0.0 0.0
        H 4. -2.757 2.857
        H 4. 2.757 2.857'''
        mol5.basis = '3-21g'
        mol5.build()

        sub1 = ClusterEnvSubSystem(mol1, 'lda', env_order=1)
        sub2 = ClusterEnvSubSystem(mol2, 'lda', env_order=1)
        sub3 = ClusterEnvSubSystem(mol3, 'pbe', env_order=2)
        sub4 = ClusterEnvSubSystem(mol4, 'm06', env_order=3)
        sub5 = ClusterHLSubSystem(mol5, 'm06', 'rhf', env_order=3)
        subsystems = [sub1, sub2, sub3, sub4, sub5]

        sup1_alt_sub_mol = gto.Mole()
        sup1_alt_sub_mol.verbose = 3
        sup1_alt_sub_mol.atom = '''
        O-0 2.0 0.0 0.0
        H-0 2. -2.757 2.857
        H-0 2. 2.757 2.857
        O-1 3.0 0.0 0.0
        H-1 3. -2.757 2.857
        H-1 3. 2.757 2.857
        O-2 4.0 0.0 0.0
        H-2 4. -2.757 2.857
        H-2 4. 2.757 2.857'''
        sup1_alt_sub_mol.basis = {
            'O-0': '6-31g',
            'H-0': '6-31g',
            'O-1': 'aug-cc-pVTZ',
            'H-1': 'aug-cc-pVTZ',
            'O-2': '3-21g',
            'H-2': '3-21g'
        }
        sup1_alt_sub_mol.build()
        sup1_alt_sub = ClusterEnvSubSystem(sup1_alt_sub_mol,
                                           'pbe',
                                           env_order=2)
        mol123 = helpers.concat_mols([sub1.mol, sub2.mol, sup1_alt_sub.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol123, 'lda', conv_tol=1e-9)
        supersystem_1 = ClusterSuperSystem([sub1, sub2, sup1_alt_sub], 'lda',
                                           fs_scf_obj)

        sup2_alt_sub_mol = gto.Mole()
        sup2_alt_sub_mol.verbose = 3
        sup2_alt_sub_mol.atom = '''
        O-0 3.0 0.0 0.0
        H-0 3. -2.757 2.857
        H-0 3. 2.757 2.857
        O-1 4.0 0.0 0.0
        H-1 4. -2.757 2.857
        H-1 4. 2.757 2.857'''
        sup2_alt_sub_mol.basis = {
            'O-0': 'aug-cc-pVTZ',
            'H-0': 'aug-cc-pVTZ',
            'O-1': '3-21g',
            'H-1': '3-21g'
        }

        sup2_alt_sub_mol.build()
        sup2_alt_sub = ClusterEnvSubSystem(sup2_alt_sub_mol,
                                           'm06',
                                           env_order=3)
        mol123 = helpers.concat_mols([sub3.mol, sup2_alt_sub.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol123, 'pbe', unrestricted=True)
        supersystem_2 = ClusterSuperSystem([sub3, sup2_alt_sub],
                                           'pbe',
                                           fs_scf_obj,
                                           env_order=2,
                                           unrestricted=True)
        mol123 = helpers.concat_mols([sub4.mol, sub5.mol])
        fs_scf_obj = helpers.gen_scf_obj(mol123, 'm06', max_cycle=10)
        supersystem_3 = ClusterSuperSystem([sub4, sub5],
                                           'm06',
                                           fs_scf_obj,
                                           env_order=3)
        supersystem_list = [supersystem_1, supersystem_2, supersystem_3]

        supersystem_dicts = [{
            'env_order': 1,
            'fs_env_settings': {
                'conv_tol': 1e-9,
                'env_method': 'lda'
            }
        }, {
            'env_order': 2,
            'fs_env_settings': {
                'unrestricted': True,
                'env_method': 'pbe'
            }
        }, {
            'env_order': 3,
            'fs_env_settings': {
                'env_method': 'm06',
                'max_cycle': 10
            }
        }]
        mediator = InteractionMediator(subsystems, supersystem_dicts)
        #Ensure the densities are the same and the methods are correct should be enough.
        self.assertEqual(len(mediator.supersystems), 3)
        for i in range(len(mediator.supersystems)):
            test = mediator.supersystems[i]
            self.assertEqual(test.env_method, supersystem_list[i].env_method)
            self.assertEqual(test.fs_scf_obj.conv_tol,
                             supersystem_list[i].fs_scf_obj.conv_tol)
            if hasattr(test.fs_scf_obj, 'unrestricted'):
                self.assertEqual(test.fs_scf_obj.unrestricted,
                                 supersystem_list[i].fs_scf_obj.unrestricted)
            self.assertEqual(test.fs_scf_obj.max_cycle,
                             supersystem_list[i].fs_scf_obj.max_cycle)