Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Manybody Implementation #879

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qcarchivetesting/conda-envs/fulltest_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:

# QCFractal Services
- torsiondrive
- qcmanybody

- pip:
- "geometric @ git+https://github.com/leeping/geomeTRIC"
Expand Down
1 change: 1 addition & 0 deletions qcarchivetesting/conda-envs/fulltest_snowflake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:

# QCFractal Services
- torsiondrive
- qcmanybody

# Worker codes below
- qcengine<0.70a0
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
_, ids = client.add_manybodys(
[molecule],
program=test_data["specification"]["program"],
singlepoint_specification=test_data["specification"]["singlepoint_specification"],
bsse_correction=test_data["specification"]["bsse_correction"],
levels=test_data["specification"]["levels"],
keywords=test_data["specification"]["keywords"],
)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
42 changes: 35 additions & 7 deletions qcarchivetesting/qcarchivetesting/test_full_manybody.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def test_manybody_full_1(fulltest_client: PortalClient):
"keywords": {"e_convergence": 1e-10, "d_convergence": 1e-10},
}

mb_keywords = {"max_nbody": None, "bsse_correction": "none"}
levels = {1: sp_spec, 2: sp_spec, 3: sp_spec, 4: sp_spec}

meta, ids = fulltest_client.add_manybodys(
initial_molecules=[molecule], program="manybody", singlepoint_specification=sp_spec, keywords=mb_keywords
initial_molecules=[molecule],
program="qcmanybody",
bsse_correction=["nocp"],
levels=levels,
keywords={"return_total_data": True},
)

for i in range(240):
Expand All @@ -49,18 +53,42 @@ def test_manybody_full_2(fulltest_client: PortalClient):
fragments=[[0], [1], [2], [3]],
)

sp_spec = {
sp_spec_1 = {
"program": "psi4",
"driver": "energy",
"method": "mp2",
"basis": "aug-cc-pvdz",
"keywords": {"e_convergence": 1e-10, "d_convergence": 1e-10},
"basis": "sto-3g",
"keywords": {"cc_type": "df", "df_basis_mp2": "def2-qzvpp-ri"},
}

sp_spec_2 = {
"program": "psi4",
"driver": "energy",
"method": "b3lyp",
"basis": "sto-3g",
"keywords": {"cc_type": "df", "df_basis_mp2": "def2-qzvpp-ri"},
}

sp_spec_3 = {
"program": "psi4",
"driver": "energy",
"method": "hf",
"basis": "sto-3g",
"keywords": {"cc_type": "df", "df_basis_mp2": "def2-qzvpp-ri"},
}

mb_keywords = {"max_nbody": 2, "bsse_correction": "cp"}
levels = {
1: sp_spec_1,
2: sp_spec_2,
"supersystem": sp_spec_3,
}

meta, ids = fulltest_client.add_manybodys(
initial_molecules=[molecule], program="manybody", singlepoint_specification=sp_spec, keywords=mb_keywords
initial_molecules=[molecule],
program="qcmanybody",
bsse_correction=["nocp", "cp", "vmfc"],
levels=levels,
keywords={"return_total_data": True},
)

for i in range(240):
Expand Down
1 change: 1 addition & 0 deletions qcfractal/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
[project.optional-dependencies]
services = [
"torsiondrive",
"qcmanybody",
]
geoip = [
"geoip2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""delete old manybody

Revision ID: a5a701dc344d
Revises: 73b4838a6839
Create Date: 2024-06-11 15:51:11.380308

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "a5a701dc344d"
down_revision = "73b4838a6839"
branch_labels = None
depends_on = None


def upgrade():

conn = op.get_bind()

res = conn.execute(sa.text("SELECT count(*) FROM base_record WHERE record_type = 'manybody'"))
count = res.fetchone()[0]
if count != 0:
raise ValueError("Will not delete old manybody tables with existing data")

res = conn.execute(sa.text("SELECT count(*) FROM manybody_record"))
count = res.fetchone()[0]
if count != 0:
raise ValueError("Will not delete old manybody tables with existing data")

res = conn.execute(sa.text("SELECT count(*) FROM manybody_dataset"))
count = res.fetchone()[0]
if count != 0:
raise ValueError("Will not delete old manybody tables with existing data")

op.execute(sa.text("DROP TABLE manybody_cluster CASCADE"))
op.execute(sa.text("DROP TABLE manybody_dataset CASCADE"))
op.execute(sa.text("DROP TABLE manybody_dataset_entry CASCADE"))
op.execute(sa.text("DROP TABLE manybody_dataset_record CASCADE"))
op.execute(sa.text("DROP TABLE manybody_dataset_specification CASCADE"))
op.execute(sa.text("DROP TABLE manybody_record CASCADE"))
op.execute(sa.text("DROP TABLE manybody_specification CASCADE"))


def downgrade():
raise NotImplementedError("Downgrade not supported")
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
"""new manybody code

Revision ID: fd95035b773b
Revises: a5a701dc344d
Create Date: 2024-06-11 16:29:38.468745

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "fd95035b773b"
down_revision = "a5a701dc344d"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"manybody_specification",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("program", sa.String(), nullable=False),
sa.Column("bsse_correction", postgresql.ARRAY(sa.String()), nullable=False),
sa.Column("keywords", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column("protocols", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column("specification_hash", sa.String(), nullable=False),
sa.CheckConstraint("program = LOWER(program)", name="ck_manybody_specification_program_lower"),
sa.PrimaryKeyConstraint("id"),
)
op.create_index("ix_manybody_specification_program", "manybody_specification", ["program"], unique=False)
op.create_table(
"manybody_specification_levels",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("manybody_specification_id", sa.Integer(), nullable=False),
sa.Column("level", sa.Integer(), nullable=False),
sa.Column("singlepoint_specification_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["manybody_specification_id"],
["manybody_specification.id"],
),
sa.ForeignKeyConstraint(
["singlepoint_specification_id"],
["qc_specification.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("manybody_specification_id", "level", name="ux_manybody_specification_levels_unique"),
)
op.create_index(
"ix_manybody_specifications_levels_manybody_specification_id",
"manybody_specification_levels",
["manybody_specification_id"],
unique=False,
)
op.create_index(
"ix_manybody_specifications_levels_singlepoint_specification_id",
"manybody_specification_levels",
["singlepoint_specification_id"],
unique=False,
)
op.create_table(
"manybody_dataset",
sa.Column("id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(["id"], ["base_dataset.id"], ondelete="cascade"),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"manybody_record",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("initial_molecule_id", sa.Integer(), nullable=False),
sa.Column("specification_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(["id"], ["base_record.id"], ondelete="cascade"),
sa.ForeignKeyConstraint(
["initial_molecule_id"],
["molecule.id"],
),
sa.ForeignKeyConstraint(
["specification_id"],
["manybody_specification.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"manybody_cluster",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("manybody_id", sa.Integer(), nullable=True),
sa.Column("molecule_id", sa.Integer(), nullable=False),
sa.Column("mc_level", sa.String(), nullable=False),
sa.Column("fragments", postgresql.ARRAY(sa.Integer()), nullable=False),
sa.Column("basis", postgresql.ARRAY(sa.Integer()), nullable=False),
sa.Column("singlepoint_id", sa.Integer(), nullable=True),
sa.CheckConstraint("array_length(basis, 1) > 0", name="ck_manybody_cluster_basis"),
sa.CheckConstraint("array_length(fragments, 1) > 0", name="ck_manybody_cluster_fragments"),
sa.ForeignKeyConstraint(["manybody_id"], ["manybody_record.id"], ondelete="cascade"),
sa.ForeignKeyConstraint(
["molecule_id"],
["molecule.id"],
),
sa.ForeignKeyConstraint(
["singlepoint_id"],
["singlepoint_record.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("manybody_id", "mc_level", "fragments", "basis", name="ux_manybody_cluster_unique"),
)
op.create_index("ix_manybody_cluster_molecule_id", "manybody_cluster", ["molecule_id"], unique=False)
op.create_index("ix_manybody_cluster_singlepoint_id", "manybody_cluster", ["singlepoint_id"], unique=False)
op.create_table(
"manybody_dataset_entry",
sa.Column("dataset_id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("comment", sa.String(), nullable=True),
sa.Column("initial_molecule_id", sa.Integer(), nullable=False),
sa.Column("additional_singlepoint_keywords", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column("attributes", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.ForeignKeyConstraint(["dataset_id"], ["manybody_dataset.id"], ondelete="cascade"),
sa.ForeignKeyConstraint(
["initial_molecule_id"],
["molecule.id"],
),
sa.PrimaryKeyConstraint("dataset_id", "name"),
)
op.create_index("ix_manybody_dataset_entry_dataset_id", "manybody_dataset_entry", ["dataset_id"], unique=False)
op.create_index(
"ix_manybody_dataset_entry_initial_molecule_id", "manybody_dataset_entry", ["initial_molecule_id"], unique=False
)
op.create_index("ix_manybody_dataset_entry_name", "manybody_dataset_entry", ["name"], unique=False)
op.create_table(
"manybody_dataset_specification",
sa.Column("dataset_id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("description", sa.String(), nullable=True),
sa.Column("specification_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(["dataset_id"], ["manybody_dataset.id"], ondelete="cascade"),
sa.ForeignKeyConstraint(
["specification_id"],
["manybody_specification.id"],
),
sa.PrimaryKeyConstraint("dataset_id", "name"),
)
op.create_index(
"ix_manybody_dataset_specification_dataset_id", "manybody_dataset_specification", ["dataset_id"], unique=False
)
op.create_index("ix_manybody_dataset_specification_name", "manybody_dataset_specification", ["name"], unique=False)
op.create_index(
"ix_manybody_dataset_specification_specification_id",
"manybody_dataset_specification",
["specification_id"],
unique=False,
)
op.create_table(
"manybody_dataset_record",
sa.Column("dataset_id", sa.Integer(), nullable=False),
sa.Column("entry_name", sa.String(), nullable=False),
sa.Column("specification_name", sa.String(), nullable=False),
sa.Column("record_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["dataset_id", "entry_name"],
["manybody_dataset_entry.dataset_id", "manybody_dataset_entry.name"],
onupdate="cascade",
ondelete="cascade",
),
sa.ForeignKeyConstraint(
["dataset_id", "specification_name"],
["manybody_dataset_specification.dataset_id", "manybody_dataset_specification.name"],
onupdate="cascade",
ondelete="cascade",
),
sa.ForeignKeyConstraint(["dataset_id"], ["manybody_dataset.id"], ondelete="cascade"),
sa.ForeignKeyConstraint(
["record_id"],
["manybody_record.id"],
),
sa.PrimaryKeyConstraint("dataset_id", "entry_name", "specification_name"),
)
op.create_index("ix_manybody_dataset_record_record_id", "manybody_dataset_record", ["record_id"], unique=False)

op.execute(
"""CREATE TRIGGER qca_manybody_record_delete_base_tr
AFTER DELETE ON public.manybody_record
FOR EACH ROW EXECUTE FUNCTION qca_base_record_delete();"""
)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_manybody_dataset_record_record_id", table_name="manybody_dataset_record")
op.drop_table("manybody_dataset_record")
op.drop_index("ix_manybody_dataset_specification_specification_id", table_name="manybody_dataset_specification")
op.drop_index("ix_manybody_dataset_specification_name", table_name="manybody_dataset_specification")
op.drop_index("ix_manybody_dataset_specification_dataset_id", table_name="manybody_dataset_specification")
op.drop_table("manybody_dataset_specification")
op.drop_index("ix_manybody_dataset_entry_name", table_name="manybody_dataset_entry")
op.drop_index("ix_manybody_dataset_entry_initial_molecule_id", table_name="manybody_dataset_entry")
op.drop_index("ix_manybody_dataset_entry_dataset_id", table_name="manybody_dataset_entry")
op.drop_table("manybody_dataset_entry")
op.drop_index("ix_manybody_cluster_singlepoint_id", table_name="manybody_cluster")
op.drop_index("ix_manybody_cluster_molecule_id", table_name="manybody_cluster")
op.drop_table("manybody_cluster")
op.drop_table("manybody_record")
op.drop_table("manybody_dataset")
op.drop_index(
"ix_manybody_specifications_levels_singlepoint_specification_id", table_name="manybody_specification_levels"
)
op.drop_index(
"ix_manybody_specifications_levels_manybody_specification_id", table_name="manybody_specification_levels"
)
op.drop_table("manybody_specification_levels")
op.drop_index("ix_manybody_specification_program", table_name="manybody_specification")
op.drop_table("manybody_specification")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""merge manybody branch with changes

Revision ID: d5988aa750ae
Revises: 3690c677f8d1, fd95035b773b
Create Date: 2025-01-14 10:49:27.547435

"""

# revision identifiers, used by Alembic.
revision = "d5988aa750ae"
down_revision = ("3690c677f8d1", "fd95035b773b")
branch_labels = None
depends_on = None


def upgrade():
pass


def downgrade():
pass
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ManybodyDatasetEntryORM(BaseORM):
comment = Column(String)

initial_molecule_id = Column(Integer, ForeignKey(MoleculeORM.id), nullable=False)
additional_keywords = Column(JSONB, nullable=False)
additional_singlepoint_keywords = Column(JSONB, nullable=False)
attributes = Column(JSONB, nullable=False)

initial_molecule = relationship(MoleculeORM, lazy="joined")
Expand Down
Loading
Loading