コード例 #1
0
ファイル: test_job.py プロジェクト: lilyminium/psiresp
    def test_restrained(self, dmso, fractal_client):
        options = RespOptions(stage_2=True, restrained_fit=True)
        job = Job(molecules=[dmso], resp_options=options)
        job.run(client=fractal_client)

        resp_1 = [[
            -0.31436216, 0.11376836, 0.14389443, 0.15583112, 0.30951582,
            -0.50568553, -0.33670393, 0.15982115, 0.12029174, 0.153629
        ]]
        resp_2 = [[
            -0.25158642, 0.11778735, 0.11778735, 0.11778735, 0.30951582,
            -0.50568553, -0.29298059, 0.12912489, 0.12912489, 0.12912489
        ]]
        assert_allclose(job.stage_1_charges.restrained_charges,
                        resp_1,
                        atol=1e-5)
        assert_allclose(job.stage_2_charges.restrained_charges,
                        resp_2,
                        atol=1e-5)
コード例 #2
0
ファイル: test_job.py プロジェクト: lilyminium/psiresp
    def test_unrestrained(self, dmso, fractal_client):
        options = RespOptions(stage_2=True, restrained_fit=False)
        job = Job(molecules=[dmso], resp_options=options)
        job.run(client=fractal_client)

        esp_1 = [[
            -0.43877469, 0.14814998, 0.17996033, 0.18716814, 0.35743529,
            -0.5085439, -0.46067469, 0.19091725, 0.15500465, 0.18935764
        ]]
        esp_2 = [[
            -0.39199538, 0.15716631, 0.15716631, 0.15716631, 0.35743529,
            -0.5085439, -0.43701446, 0.16953984, 0.16953984, 0.16953984
        ]]
        assert_allclose(job.stage_1_charges.unrestrained_charges,
                        esp_1,
                        atol=1e-7)
        assert_allclose(job.stage_2_charges.unrestrained_charges,
                        esp_2,
                        atol=1e-7)

        chgrepr = """<RespCharges(restraint_height=0.0005, restraint_slope=0.1, restrained_fit=False, exclude_hydrogens=True) with 0 charge constraints; unrestrained_charges=[array([-0.43877,  0.14815,  0.17996,  0.18717,  0.35744, -0.50854,
       -0.46067,  0.19092,  0.155  ,  0.18936])], restrained_charges=None>"""
        assert repr(job.stage_1_charges) == chgrepr
コード例 #3
0
ファイル: test_job.py プロジェクト: lilyminium/psiresp
    def test_run_manual(self, nme2ala2_empty, methylammonium_empty, tmpdir):
        pytest.importorskip("rdkit")

        nme2ala2_empty.optimize_geometry = True
        methylammonium_empty.optimize_geometry = True
        assert len(nme2ala2_empty.conformers) == 2
        assert len(methylammonium_empty.conformers) == 1
        job = Job(molecules=[methylammonium_empty, nme2ala2_empty])

        data_wkdir = pathlib.Path(MANUAL_JOBS_WKDIR)

        with tmpdir.as_cwd():

            # OPTIMIZATION
            assert not job.working_directory.exists()
            with pytest.raises(SystemExit, match="Exiting to allow running"):
                job.run()

            assert job.working_directory.exists()

            # check run file contents
            runfile = job.qm_optimization_options.get_run_file(
                job.working_directory)
            assert str(
                runfile
            ) == "psiresp_working_directory/optimization/run_optimization.sh"
            with runfile.open() as f:
                optlines = [x.strip() for x in f.readlines()]
            assert len(optlines) == 4

            # check existence and copy completed files in
            opt_filenames = glob.glob(str(data_wkdir / "optimization/*"))
            assert len(opt_filenames) == 4
            for file in opt_filenames:
                path = pathlib.Path(file.split("manual_jobs/")[1])
                assert path.exists()

                if file.endswith("msgpack"):
                    assert f"psi4 --qcschema {path.name}" in optlines
                shutil.copyfile(file, path)

            assert all(not conf.is_optimized for conf in job.iter_conformers())

            # SINGLE POINT
            assert not job.qm_esp_options.get_working_directory(
                job.working_directory).exists()
            with pytest.raises(SystemExit, match="Exiting to allow running"):
                job.run()

            assert all(conf.is_optimized for conf in job.iter_conformers())

            # check run file contents
            runfile = job.qm_esp_options.get_run_file(job.working_directory)
            assert str(
                runfile
            ) == "psiresp_working_directory/single_point/run_single_point.sh"
            with runfile.open() as f:
                splines = [x.strip() for x in f.readlines()]
            assert len(splines) == 11

            # check existence and copy completed files in
            opt_filenames = glob.glob(str(data_wkdir / "single_point/*"))
            assert len(opt_filenames) == 11
            for file in opt_filenames:
                path = pathlib.Path(file.split("manual_jobs/")[1])
                assert path.exists()

                if file.endswith("msgpack"):
                    assert f"psi4 --qcschema {path.name}" in splines
                shutil.copyfile(file, path)

            job.run()
            methylammonium_charges = [
                -0.281849, 0.174016, 0.174016, 0.174016, -0.528287, 0.215501,
                0.857086, 0.215501
            ]
            nme2ala2_charges = [
                4.653798, -1.174226, -1.1742263, -1.1742263, -1.2224316,
                0.1732717, -3.9707787, 0.8309516, 8.291471, 4.749616,
                -1.870866, -1.870866, -1.870866, 2.275405, -1.3199896,
                -1.3199896, -1.3199896, 1.6195477, -1.5787892, -14.898019,
                2.9755072, 30.303230, -7.035844, -7.035844, -7.035844
            ]

            assert_allclose(job.charges[0], methylammonium_charges, atol=1e-6)
            assert_allclose(job.charges[1], nme2ala2_charges, atol=1e-6)