from genice_core.water import molecules_iter, tip4p


def render(
    dg,
    layout: dict,
    title="Generated by Gromify",
    cell="30.0 30.0 30.0",
    watermodel=tip4p,
    pbc=False,
):
    s = ""

    natom = 0
    for water, atomtypes in molecules_iter(
        dg, layout, watermodel=watermodel, pbc=pbc
    ):
        natom += len(water)
        for i, site in enumerate(atomtypes):
            #            s += f"{1:>5}DOD  {site:5}{i:>5}{water[i,0]:>8.3f}{water[i,1]:>8.3f}{water[i,2]:>8.3f}\n"
            s += f"{1:>5}DOD  {site:5}{i:>4}{water[i,0]:>8.3f}{water[i,1]:>8.3f}{water[i,2]:>8.3f}\n"

    head = title + "\n"
    head += f"{natom}\n"
    tail = cell + "\n"
    return head + s + tail
