import importlib_resources
import pytest

from pydirac.core.molecule import Molecule
from pydirac.io.sets import *

dir_out_He = str(
    importlib_resources.files("pydirac.tests.data.He_q_so") / "d-aug-dyall.acv3z_+0.00001"
)


@pytest.fixture
def cc_set():
    return AtomicCCSet(molecule=Molecule(["Mc"], [[0.0, 0.0, 0.0]]))


# @pytest.mark.skip(reason="not implemented yet")
def test_atomic_cc_set_inp(cc_set):
    inp_from_code = cc_set.inp
    inp_from_dict = {
        "DIRAC": {
            "TITLE": "DIRAC input file generated by PYDIRAC",
            "WAVE F": True,
            "ANALYZE": True,
            "4INDEX": True,
        },
        "ANALYZE": {
            "MULPOP": {
                "_en": True,
                "VECPOP": "1..oo",
            }
        },
        "HAMILTONIAN": {
            "DOSSSS": True,
            "X2C": False,
            "NOSPIN": False,
        },
        "INTEGRALS": {
            "READINP": "UNCONTRACT",
        },
        "WAVE FUNCTIONS": {
            "RESOLVE": True,
            "SCF": {
                "_en": True,
                "EVCCNV": "1.0D-9 5.0D-8",
                "MAXITR": 60,
                "CLOSED SHELL": "112",
                "OPEN SHELL": "1\n3/6",
            },
            "RELCCSD": True,
        },
        "MOLTRA": {
            "ACTIVE": "-20.0 25.0 0.01",
        },
        "RELCC": {
            "ENERGY": True,
            "PRINT": 1,
            "CCENER": True,
            "MAXIT": 60,
            "NTOL": 10,
        },
    }
    assert inp_from_code == inp_from_dict


def test_atomic_cc_set_mol(cc_set):
    mol_from_code = {
        "basis_type": cc_set.mol.basis_type,
        "basis_lib": cc_set.mol.basis_lib,
    }
    mol_from_dict = {
        "basis_type": "dyall.v3z",
        "basis_lib": "BASIS",
    }
    assert mol_from_code == mol_from_dict


def test_atomic_cc_set_from_prev_calc():
    new_cc = AtomicCCSet.from_prev_calc(
        dir_out_He, no_scf=True, user_mol_settings={"basis_type": "s-aug-ANO-RCC"}
    )
    assert new_cc.inp is not None
    assert new_cc.mol is not None
