# Path: acpype/acs_api.py
# def acpype_api(
#     inputFile,
#     chargeType="bcc",
#     chargeVal=None,
#     multiplicity="1",
#     atomType="gaff2",
#     force=False,
#     basename=None,
#     debug=False,
#     outTopol="all",
#     engine="tleap",
#     allhdg=False,
#     timeTol=MAXTIME,
#     qprog="sqm",
#     ekFlag=None,
#     verbose=True,
#     gmx4=False,
#     merge=False,
#     direct=False,
#     is_sorted=False,
#     chiral=False,
#     is_smiles=False,
# ):
# 
#     at0 = time.time()
#     print(header)
# 
#     if debug:
#         texta = "Python Version %s" % sys.version
#         print("DEBUG: %s" % while_replace(texta))
#     try:
#         molecule = ACTopol(
#             inputFile=inputFile,
#             chargeType=chargeType,
#             chargeVal=chargeVal,
#             debug=debug,
#             multiplicity=multiplicity,
#             atomType=atomType,
#             force=force,
#             outTopol=outTopol,
#             allhdg=allhdg,
#             basename=basename,
#             timeTol=timeTol,
#             qprog=qprog,
#             ekFlag=ekFlag,
#             verbose=verbose,
#             gmx4=gmx4,
#             merge=merge,
#             direct=direct,
#             is_sorted=is_sorted,
#             chiral=chiral,
#         )
# 
#         molecule.createACTopol()
#         molecule.createMolTopol()
# 
#         "Output in JSON format"
#         os.chdir(molecule.absHomeDir)
#         readFiles(molecule.baseName, chargeType, atomType)
#         output = {
#             "file_name": molecule.baseName,
#             "em_mdp": em_mdp.getvalue(),
#             "AC_frcmod": AC_frcmod.getvalue(),
#             "AC_inpcrd": AC_inpcrd.getvalue(),
#             "AC_lib": AC_lib.getvalue(),
#             "AC_prmtop": AC_prmtop.getvalue(),
#             "mol2": mol2.getvalue(),
#             "CHARMM_inp": CHARMM_inp.getvalue(),
#             "CHARMM_prm": CHARMM_prm.getvalue(),
#             "CHARMM_rtf": CHARMM_rtf.getvalue(),
#             "CNS_inp": CNS_inp.getvalue(),
#             "CNS_par": CNS_par.getvalue(),
#             "CNS_top": CNS_top.getvalue(),
#             "GMX_OPLS_itp": GMX_OPLS_itp.getvalue(),
#             "GMX_OPLS_top": GMX_OPLS_top.getvalue(),
#             "GMX_gro": GMX_gro.getvalue(),
#             "GMX_itp": GMX_itp.getvalue(),
#             "GMX_top": GMX_top.getvalue(),
#             "NEW_pdb": NEW_pdb.getvalue(),
#             "md_mdp": md_mdp.getvalue(),
#         }
# 
#     except Exception:
#         _exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
#         print("ACPYPE FAILED: %s" % exceptionValue)
#         if debug:
#             traceback.print_tb(exceptionTraceback, file=sys.stdout)
#             output = {"file_name": f"ERROR: {str(exceptionValue)}"}
# 
#     execTime = int(round(time.time() - at0))
#     if execTime == 0:
#         amsg = "less than a second"
#     else:
#         amsg = elapsedTime(execTime)
#     print("Total time of execution: %s" % amsg)
#     clearFileInMemory()
#     try:
#         shutil.rmtree(molecule.absHomeDir)
#     except Exception:
#         print("DEBUG: No folder left to be removed")
#     return json.dumps(output)


import json
from glob import glob
from acpype.acs_api import acpype_api
    ("CHARMM_rtf"),
    ("CNS_inp"),
    ("CNS_par"),
    ("CNS_top"),
    ("GMX_OPLS_itp"),
    ("GMX_OPLS_top"),
    ("GMX_gro"),
    ("GMX_itp"),
    ("GMX_top"),
    ("NEW_pdb"),
    ("md_mdp"),
)


def test_json_simple(janitor):
    jj = json.loads(acpype_api(inputFile="benzene.pdb", debug=True))
    assert min(len(jj.get(x)) for x in file_types) >= 7
    assert jj.get("file_name") == "benzene"
    janitor.append("../.acpype_tmp_benzene")


def test_json_failed(janitor):
    jj = json.loads(acpype_api(inputFile="_fake_", debug=True))
    assert "ERROR: [Errno 2] No such file or directory" in jj.get("file_name")
    assert "tests/_fake_" in jj.get("file_name")
    for ii in glob(".*_fake_*"):
        janitor.append(ii)


def get_json():

# Path: acpype/acs_api.py
# def acpype_api(
#     inputFile,
#     chargeType="bcc",
#     chargeVal=None,
#     multiplicity="1",
#     atomType="gaff2",
#     force=False,
#     basename=None,
#     debug=False,
#     outTopol="all",
#     engine="tleap",
#     allhdg=False,
#     timeTol=MAXTIME,
#     qprog="sqm",
#     ekFlag=None,
#     verbose=True,
#     gmx4=False,
#     merge=False,
#     direct=False,
#     is_sorted=False,
#     chiral=False,
#     is_smiles=False,
# ):
# 
#     at0 = time.time()
#     print(header)
# 
#     if debug:
#         texta = "Python Version %s" % sys.version
#         print("DEBUG: %s" % while_replace(texta))
#     try:
#         molecule = ACTopol(
#             inputFile=inputFile,
#             chargeType=chargeType,
#             chargeVal=chargeVal,
#             debug=debug,
#             multiplicity=multiplicity,
#             atomType=atomType,
#             force=force,
#             outTopol=outTopol,
#             allhdg=allhdg,
#             basename=basename,
#             timeTol=timeTol,
#             qprog=qprog,
#             ekFlag=ekFlag,
#             verbose=verbose,
#             gmx4=gmx4,
#             merge=merge,
#             direct=direct,
#             is_sorted=is_sorted,
#             chiral=chiral,
#         )
# 
#         molecule.createACTopol()
#         molecule.createMolTopol()
# 
#         "Output in JSON format"
#         os.chdir(molecule.absHomeDir)
#         readFiles(molecule.baseName, chargeType, atomType)
#         output = {
#             "file_name": molecule.baseName,
#             "em_mdp": em_mdp.getvalue(),
#             "AC_frcmod": AC_frcmod.getvalue(),
#             "AC_inpcrd": AC_inpcrd.getvalue(),
#             "AC_lib": AC_lib.getvalue(),
#             "AC_prmtop": AC_prmtop.getvalue(),
#             "mol2": mol2.getvalue(),
#             "CHARMM_inp": CHARMM_inp.getvalue(),
#             "CHARMM_prm": CHARMM_prm.getvalue(),
#             "CHARMM_rtf": CHARMM_rtf.getvalue(),
#             "CNS_inp": CNS_inp.getvalue(),
#             "CNS_par": CNS_par.getvalue(),
#             "CNS_top": CNS_top.getvalue(),
#             "GMX_OPLS_itp": GMX_OPLS_itp.getvalue(),
#             "GMX_OPLS_top": GMX_OPLS_top.getvalue(),
#             "GMX_gro": GMX_gro.getvalue(),
#             "GMX_itp": GMX_itp.getvalue(),
#             "GMX_top": GMX_top.getvalue(),
#             "NEW_pdb": NEW_pdb.getvalue(),
#             "md_mdp": md_mdp.getvalue(),
#         }
# 
#     except Exception:
#         _exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
#         print("ACPYPE FAILED: %s" % exceptionValue)
#         if debug:
#             traceback.print_tb(exceptionTraceback, file=sys.stdout)
#             output = {"file_name": f"ERROR: {str(exceptionValue)}"}
# 
#     execTime = int(round(time.time() - at0))
#     if execTime == 0:
#         amsg = "less than a second"
#     else:
#         amsg = elapsedTime(execTime)
#     print("Total time of execution: %s" % amsg)
#     clearFileInMemory()
#     try:
#         shutil.rmtree(molecule.absHomeDir)
#     except Exception:
#         print("DEBUG: No folder left to be removed")
#     return json.dumps(output)


# Path: tests/test_acs_api.py
import json
from glob import glob
from acpype.acs_api import acpype_api

    ("CHARMM_rtf"),
    ("CNS_inp"),
    ("CNS_par"),
    ("CNS_top"),
    ("GMX_OPLS_itp"),
    ("GMX_OPLS_top"),
    ("GMX_gro"),
    ("GMX_itp"),
    ("GMX_top"),
    ("NEW_pdb"),
    ("md_mdp"),
)


def test_json_simple(janitor):
    jj = json.loads(acpype_api(inputFile="benzene.pdb", debug=True))
    assert min(len(jj.get(x)) for x in file_types) >= 7
    assert jj.get("file_name") == "benzene"
    janitor.append("../.acpype_tmp_benzene")


def test_json_failed(janitor):
    jj = json.loads(acpype_api(inputFile="_fake_", debug=True))
    assert "ERROR: [Errno 2] No such file or directory" in jj.get("file_name")
    assert "tests/_fake_" in jj.get("file_name")
    for ii in glob(".*_fake_*"):
        janitor.append(ii)


def get_json():

    json_output = acpype_api(inputFile="AAA.mol2", chargeType="gas", atomType="gaff2", debug=True, basename="AAA")