Пример #1
0
def test_merge(janitor, merge, gaff, n_at, acoef, bcoef, msg):
    molecule = MolTopol(acFileTop=f"ComplexG{gaff}.prmtop", acFileXyz=f"ComplexG{gaff}.inpcrd", debug=True, merge=merge)
    molecule.writeGromacsTopolFiles()
    assert molecule
    assert len(molecule.atomTypesGromacs) == n_at
    assert molecule.atomTypesGromacs[31].ACOEF == acoef
    assert molecule.atomTypesGromacs[31].BCOEF == bcoef
    assert molecule.atomTypesGromacs[31].__repr__() == msg
    janitor.append(molecule.absHomeDir)
Пример #2
0
def test_ildn(janitor, mol, n1, n2, n3, n4, n5, msg):
    molecule = MolTopol(acFileTop=f"{mol}.prmtop", acFileXyz=f"{mol}.inpcrd", debug=True)
    molecule.writeGromacsTopolFiles()
    assert molecule
    assert len(molecule.atoms) == n1
    assert len(molecule.properDihedrals) == n2
    assert len(molecule.improperDihedrals) == n3
    assert molecule.totalCharge == n4
    assert len(molecule.atomTypes) == n5
    assert molecule.atomTypes[23].__repr__() == msg
    janitor.append(molecule.absHomeDir)
Пример #3
0
def test_amb2gmx(janitor, dd, g4, ntext):
    # oct box with water and ions
    # modified from https://ambermd.org/tutorials/basic/tutorial7/index.php
    # using addIonsRand separated for each ion and TIP3PBOX
    molecule = MolTopol(acFileTop="RAMP1_ion.prmtop", acFileXyz="RAMP1_ion.inpcrd", debug=True, direct=dd, gmx4=g4)
    molecule.writeGromacsTopolFiles()
    assert molecule
    assert len(molecule.topText) == ntext
    assert not molecule.topo14Data.hasNondefault14()
    assert molecule.atoms[1300].__repr__() == "<Atom id=1301, name=NA+, <AtomType=Na+>>"
    assert molecule.atoms[1310].__repr__() == "<Atom id=1311, name=CL-, <AtomType=Cl->>"
    assert len(molecule.atoms) == 18618
    janitor.append(molecule.absHomeDir)
Пример #4
0
def test_glycam(janitor):
    molecule = MolTopol(acFileTop="glycam_exe.prmtop", acFileXyz="glycam_exe.inpcrd", debug=True, amb2gmx=True)
    molecule.writeGromacsTopolFiles()
    molecule.writeCnsTopolFiles()
    assert molecule
    assert molecule.topo14Data.hasNondefault14()
    assert len(molecule.topo14Data.scnb_scale_factor) == 31
    janitor.append(molecule.absHomeDir)
Пример #5
0
def init_main(binaries: Dict[str, str] = binaries,
              argv: Optional[List[str]] = None):
    """
    Orchestrate the command line usage for ACPYPE with its all input arguments.

    Args:
        binaries (Dict[str, str], optional): Mostly used for debug and testing. Defaults to ``acpype.params.binaries``.
        argv (Optional[List[str]], optional): Mostly used for debug and testing. Defaults to None.

    Returns:
        SystemExit(status): 0 or 19 (failed)
    """
    _chk_py_ver()
    if argv is None:
        argv = sys.argv[1:]

    parser = get_option_parser()
    args = parser.parse_args(argv)

    at0 = time.time()

    amb2gmxF = False

    if args.version:
        print(header)
        sys.exit(0)

    level = 20
    if not args.verboseless:
        level = 100
    if args.debug:
        level = 10

    logger(level).info(header)

    if not args.input:
        amb2gmxF = True
        if not args.inpcrd or not args.prmtop:
            parser.error("missing input files")
    elif args.inpcrd or args.prmtop:
        parser.error("either '-i' or ('-p', '-x'), but not both")

    logger(level).debug(f"CLI: {' '.join(argv)}")
    texta = f"Python Version {sys.version}"
    logger(level).debug(while_replace(texta))

    if args.direct and not amb2gmxF:
        parser.error(
            "option -u is only meaningful in 'amb2gmx' mode (args '-p' and '-x')"
        )

    acpypeFailed = False
    if amb2gmxF:
        logger(level).info("Converting Amber input files to Gromacs ...")
        try:
            molecule: AbstractTopol = MolTopol(
                acFileXyz=args.inpcrd,
                acFileTop=args.prmtop,
                amb2gmx=True,
                debug=args.debug,
                basename=args.basename,
                verbose=args.verboseless,
                gmx4=args.gmx4,
                merge=args.merge,
                direct=args.direct,
                is_sorted=args.sorted,
                chiral=args.chiral,
            )
        except Exception:
            acpypeFailed = _handle_exception(level)
        if not acpypeFailed:
            try:
                molecule.writeGromacsTopolFiles()
                molecule.printDebug("prmtop and inpcrd files parsed")
            except Exception:
                acpypeFailed = _handle_exception(level)

    else:
        try:
            molecule = ACTopol(
                args.input,
                binaries=binaries,
                chargeType=args.charge_method,
                chargeVal=args.net_charge,
                debug=args.debug,
                multiplicity=args.multiplicity,
                atomType=args.atom_type,
                force=args.force,
                outTopol=args.outtop,
                allhdg=args.cnstop,
                basename=args.basename,
                timeTol=args.max_time,
                qprog=args.qprog,
                ekFlag=f'''"{args.keyword}"''',
                verbose=args.verboseless,
                gmx4=args.gmx4,
                merge=args.merge,
                direct=args.direct,
                is_sorted=args.sorted,
                chiral=args.chiral,
                amb2gmx=False,
            )
        except Exception:
            acpypeFailed = _handle_exception(level)
        if not acpypeFailed:
            try:
                molecule.createACTopol()
            except Exception:
                acpypeFailed = _handle_exception(level)
        if not acpypeFailed:
            try:
                molecule.createMolTopol()
            except Exception:
                acpypeFailed = _handle_exception(level)

    execTime = int(round(time.time() - at0))
    if execTime == 0:
        amsg = "less than a second"
    else:
        amsg = elapsedTime(execTime)
    logger(level).info(f"Total time of execution: {amsg}")

    if args.ipython:
        try:
            import IPython

            IPython.embed(colors="neutral")
        except ModuleNotFoundError:
            logger(level).exception("No 'ipython' installed")

    if not args.debug:
        try:
            rmtree(molecule.tmpDir)
        except Exception:
            logger(level).debug("No tmp folder left to be removed")
    else:
        try:
            if molecule.tmpDir:
                logger(level).debug(
                    f"Keeping folder '{molecule.tmpDir}' for possible helping debugging"
                )
        except Exception:
            logger(level).debug("No tmp folder left to be removed")

    try:
        copy_log(molecule)
    except UnboundLocalError:
        print(f"Log tmp location: {tmpLogFile}")

    if acpypeFailed:
        sys.exit(19)

    os.chdir(molecule.rootDir)

    if not amb2gmxF and molecule.obabelExe:
        if molecule.checkSmiles():
            afile = "smiles_molecule.mol2"
            if os.path.exists(afile):
                os.remove(afile)
Пример #6
0
def test_wrong_input(janitor):
    with pytest.raises(Exception) as e_info:
        MolTopol(acFileTop="nope.prmtop", acFileXyz="ILDN.inpcrd", debug=True, gmx4=True)
    assert e_info.value.args == (2, "No such file or directory")
Пример #7
0
def test_ildn_gmx4_fail(janitor):
    molecule = MolTopol(acFileTop="ILDN.prmtop", acFileXyz="ILDN.inpcrd", debug=True, gmx4=True)
    with pytest.raises(Exception) as e_info:
        molecule.writeGromacsTopolFiles()
    assert e_info.value.args[0] == "Likely trying to convert ILDN to RB, DO NOT use option '-z'"
    janitor.append(molecule.absHomeDir)