"""Build the starting water molecule for the vibrational-mode study.

No calculator is used. `molecule("H2O")` is the builder geometry that
water-modes-run.py relaxes:

    python water-modes-build.py --output ../models
"""
import argparse
from pathlib import Path

from atomli.build import molecule
from atomli.io import write


def main():
    here = Path(__file__).resolve().parent
    parser = argparse.ArgumentParser()
    parser.add_argument("--output", type=Path, default=here.parent / "models")
    parser.add_argument("--spec", type=Path, help="also write the viewer spec for the documentation page")
    args = parser.parse_args()
    atoms = molecule("H2O")
    args.output.mkdir(parents=True, exist_ok=True)
    write(args.output / "h2o-start.extxyz", atoms)
    if args.spec:
        from atomli.visualize import Viewer

        viewer = Viewer([atoms], height=300, look={"background": "white", "axes": True, "legend": True, "labels": True})
        viewer.write_spec(args.spec, structure_path=args.spec.with_name("h2o-start.extxyz"))


if __name__ == "__main__":
    main()
