Пример #1
0
def gen_itp(args):

    # Import of Itp and FF files
    force_field = load_library(args.name, args.lib, args.inpath)

    # Generate the MetaMolecule
    if args.seq:
        monomers = split_seq_string(args.seq)
        meta_molecule = MetaMolecule.from_monomer_seq_linear(
            monomers=monomers, force_field=force_field, mol_name=args.name)
    #ToDo
    # fix too broad except
    elif args.seq_file:
        extension = args.seq_file.suffix.casefold()[1:]
        try:
            parser = getattr(MetaMolecule, 'from_{}'.format(extension))
            meta_molecule = parser(json_file=args.seq_file,
                                   force_field=force_field,
                                   mol_name=args.name)
        except AttributeError:
            raise IOError(
                "Cannot parse file with extension {}.".format(extension))

    # Do transformationa and apply link
    meta_molecule = MapToMolecule().run_molecule(meta_molecule)
    meta_molecule = ApplyLinks().run_molecule(meta_molecule)

    with open(args.outpath, 'w') as outpath:
        vermouth.gmx.itp.write_molecule_itp(meta_molecule.molecule,
                                            outpath,
                                            moltype=args.name,
                                            header=["polyply-itp"])
    DeferredFileWriter().write()
Пример #2
0
def gen_params(name, outpath, inpath=None, lib=None, seq=None, seq_file=None):
    """
    Top level function for running the polyply parameter generation.
    Parameters seq and seq_file are mutually exclusive. Set the other
    to None. Of inpath and lib only one has to be given. Set the other
    to None if not used.

    Parameters
    ----------
    name: str
        name of the molecule in the itp file
    outpath: :class:`pathlib.Path`
        file path for output file
    inpath: list[pathlib.Path]
        list of paths to files with input definitions
    library: str
        name of the force field library to use
    seq: list[str]
        list of strings with format "resname:#monomers"
    seqf: :class:`pathlib.Path`
        file path to valid sequence file (.json/.fasta/.ig/.txt)
    """
    # Import of Itp and FF files
    LOGGER.info("reading input and library files", type="step")
    force_field = load_library(name, lib, inpath)

    # Generate the MetaMolecule
    if seq:
        LOGGER.info("reading sequence from command", type="step")
        monomers = split_seq_string(seq)
        meta_molecule = MetaMolecule.from_monomer_seq_linear(
            monomers=monomers, force_field=force_field, mol_name=name)
    elif seq_file:
        LOGGER.info("reading sequence from file", type="step")
        meta_molecule = MetaMolecule.from_sequence_file(
            force_field, seq_file, name)

    # Do transformationa and apply link
    LOGGER.info("mapping sequence to molecule", type="step")
    meta_molecule = MapToMolecule(force_field).run_molecule(meta_molecule)
    LOGGER.info("applying links between residues", type="step")
    meta_molecule = ApplyLinks().run_molecule(meta_molecule)

    # Raise warning if molecule is disconnected
    if not nx.is_connected(meta_molecule.molecule):
        LOGGER.warning("Your molecule consists of disjoint parts."
                       "Perhaps links were not applied correctly.")
        msg = "Missing link between residue {idxA} {resA} and residue {idxB} {resB}"
        for missing in find_missing_edges(meta_molecule,
                                          meta_molecule.molecule):
            LOGGER.warning(msg, **missing)

    with deferred_open(outpath, 'w') as outfile:
        header = [' '.join(sys.argv) + "\n"]
        header.append("Please cite the following papers:")
        for citation in meta_molecule.molecule.citations:
            cite_string = citation_formatter(
                meta_molecule.molecule.force_field.citations[citation])
            LOGGER.info("Please cite: " + cite_string)
            header.append(cite_string)

        vermouth.gmx.itp.write_molecule_itp(meta_molecule.molecule,
                                            outfile,
                                            moltype=name,
                                            header=header)
    DeferredFileWriter().write()