from pyscf import lib
from ..xtb import XTB
from .rhf import OPT as RHFOPT

class OPT(RHFOPT):
    def _gen_calc_block(self, data, mol):
        # pysisyphus configuration for XTB using tblite
        # This avoids dependency on external 'xtb' binary.
        data["calc"] = {
            "type": "tblite",
            "charge": mol.charge,
            "mult": mol.spin + 1,
            # tblite calculator in pysisyphus might not need 'pal' or handles it differently
            # but usually extra keys are ignored or passed.
        }
        # Pass method if it's not the default? 
        # XTB class has .method attribute (e.g. "GFN2-xTB")
        # pysisyphus 'xtb' calculator typically assumes GFN2-xTB by default or via 'par' key.
        # "GFN2-xTB" -> par: 2 (usually default)
        # "GFN1-xTB" -> par: 1
        # "GFN0-xTB" -> par: 0
        
        if self.mf.method:
            method_str = self.mf.method.upper()
            if "GFN1" in method_str:
                data["calc"]["par"] = 1
            elif "GFN0" in method_str:
                data["calc"]["par"] = 0
            # Default is usually GFN2
            
    # _run_yaml and other methods are inherited from RHFOPT

XTB.sOPT = lib.class_as_method(OPT)
