Esempio n. 1
0
    def test_makease_works_with_openshells(self):
        """Ensure makease works from parsed data for open-shell molecules."""
        # make sure we can construct an open shell molecule
        data = ccopen("data/ORCA/basicORCA4.2/dvb_sp_un.out").parse()

        # Check we have no gradients, as they will be generated by ASE.
        with self.assertRaises(AttributeError):
            data.grads

        dvb_sp_un = cclib2ase.makease(
            data.atomcoords[-1],
            data.atomnos,
            data.atomcharges["mulliken"],
            data.atomspins["mulliken"],
            data.atommasses,
        )

        # check whether converting back gives the expected data
        ase_data = cclib2ase.makecclib(dvb_sp_un)
        assert np.allclose(ase_data.atomcoords, [data.atomcoords[-1]])
        assert np.allclose(ase_data.atomnos, data.atomnos)
        assert np.allclose(ase_data.atomcharges["mulliken"],
                           data.atomcharges["mulliken"])
        assert np.allclose(ase_data.atomspins["mulliken"],
                           data.atomspins["mulliken"])
        assert np.allclose(ase_data.atommasses, data.atommasses)
        assert np.isclose(ase_data.charge, data.charge)
        assert np.isclose(ase_data.mult, data.mult)
        assert np.isclose(ase_data.natom, len(data.atomnos))
        assert np.isclose(ase_data.temperature, 0)

        # make sure our object is compatible with ASE API
        dvb_sp_un.calc = EMT(label="dvb_sp_un")  # not a serious calculator!

        # converting back should give updated results
        ase_data = cclib2ase.makecclib(dvb_sp_un)
        assert np.allclose(ase_data.atomcoords, [data.atomcoords[-1]])
        assert np.allclose(ase_data.atomnos, data.atomnos)
        assert np.allclose(ase_data.atommasses, data.atommasses)
        assert np.allclose(ase_data.atomcharges["mulliken"],
                           data.atomcharges["mulliken"])
        assert np.allclose(
            ase_data.atomspins["mulliken"],
            0)  # spin densities not supported but overwritten by EMT
        assert np.isclose(ase_data.charge, data.charge)
        assert np.isclose(ase_data.mult, 1)
        assert np.isclose(ase_data.natom, len(data.atomnos))
        assert np.isclose(ase_data.temperature, 0)

        # Both energies and gradients are from the EMT calculation.
        assert np.allclose(ase_data.scfenergies, [7.016800805424298])
        assert np.shape(ase_data.grads) == (1, ase_data.natom, 3)
Esempio n. 2
0
    def test_makecclib_retrieves_optimization(self):
        """Ensure makecclib works with native ASE Atoms objects."""
        h2 = Atoms("H2", positions=[[0, 0, 0], [0, 0, 0.7]])

        # Check whether converting back gives the expected data,
        data = cclib2ase.makecclib(h2)
        assert np.allclose(data.atomcoords, [[[0, 0, 0], [0, 0, 0.7]]])
        assert np.allclose(data.atomnos, [1, 1])
        assert np.allclose(data.atommasses, [1.008, 1.008])
        assert np.isclose(data.natom, 2)
        assert np.isclose(data.charge, 0)
        assert np.isclose(data.mult, 1)
        assert np.isclose(data.temperature, 0)
Esempio n. 3
0
    def test_makease_allows_optimization(self):
        """Ensure makease works from direct input."""
        h2 = cclib2ase.makease([[0, 0, 0], [0, 0, 0.7]], [1, 1])

        # Check whether converting back gives the expected data,
        data = cclib2ase.makecclib(h2)
        assert np.allclose(data.atomcoords, [[[0, 0, 0], [0, 0, 0.7]]])
        assert np.allclose(data.atomnos, [1, 1])
        assert np.allclose(data.atommasses, [1.008, 1.008])
        assert np.isclose(data.natom, 2)
        assert np.isclose(data.charge, 0)
        assert np.isclose(data.mult, 1)
        assert np.isclose(data.temperature, 0)
Esempio n. 4
0
    def test_makease_works_with_closedshells(self):
        """Ensure makease works from parsed data for closed-shell molecules."""
        # Make sure we can construct a closed shell molecule.
        data = ccopen("data/ORCA/basicORCA4.2/dvb_ir.out").parse()
        dvb_ir = cclib2ase.makease(
            data.atomcoords[-1],
            data.atomnos,
            data.atomcharges["mulliken"],
            None,  # no atomspins
            data.atommasses,
        )

        # check whether converting back gives the expected data.
        ase_data = cclib2ase.makecclib(dvb_ir)
        assert np.allclose(ase_data.atomcoords, [data.atomcoords[-1]])
        assert np.allclose(ase_data.atomnos, data.atomnos)
        assert np.allclose(ase_data.atomcharges["mulliken"],
                           data.atomcharges["mulliken"])
        assert np.allclose(ase_data.atomspins["mulliken"], 0)
        assert np.allclose(ase_data.atommasses, data.atommasses)
        assert np.isclose(ase_data.charge, data.charge, atol=1e-5)
        assert np.isclose(ase_data.mult, data.mult)
        assert np.isclose(ase_data.natom, len(data.atomnos))
        assert np.isclose(ase_data.temperature, 0)