Skip to content

Commit

Permalink
Merge pull request #277 from dgasmith/mol
Browse files Browse the repository at this point in the history
Client: Removes ids when printing
  • Loading branch information
dgasmith authored May 28, 2019
2 parents 7c6949a + c2638ec commit 5e464fb
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
104 changes: 104 additions & 0 deletions qcf_0_6_to_0_7_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import pymongo
import tqdm
import qcelemental as qcel
import qcfractal.interface as ptl

client = pymongo.MongoClient("localhost:27017")
client.drop_database("qcarchive2")
client.admin.command("copydb", fromdb="qcarchive", todb="qcarchive2")

db = client.qcarchive2

print("\nUpdating Molecule hashes:")
mol_query = db.molecule.find(limit=1000)
total = mol_query.count()

updates = 0

# First update molecules
for raw_mol in tqdm.tqdm(mol_query, total=total):

tmpdata = raw_mol.copy()
tmpdata.pop("_id", None)
tmpdata.pop("molecular_formula", None)
tmpdata.pop("molecule_hash", None)

conupd = False
if ("connectivity" in tmpdata) and (tmpdata["connectivity"] == []):
tmpdata["connectivity"] = None
conupd = True

mol = qcel.models.Molecule(**tmpdata, validate=False)

mhash = mol.get_hash()
if mhash == raw_mol["molecule_hash"]:
if conupd:
print(raw_mol)
raise Exception()
continue


upd_data = {"molecule_hash": mhash, "identifiers": tmpdata["identifiers"]}
upd_data["identifiers"]["molecule_hash"] = mhash
if conupd:
upd_data["connectivity"] = None

upd = db.molecule.update_one({"_id": raw_mol["_id"]}, {"$set": upd_data})
if upd.modified_count != 1:
print(upd)
print(upd_data)
break
else:
updates += 1

print(f"Total number of result updates: {updates}")


## Result updates
print("\nUpdating Result Fields:")

upd = db.result.update_many({}, {"$rename": {"extras.local_qcvars": "extras.qcvars", "properties.mp2_total_correlation_energy": "properties.mp2_correlation_energy"}})
print(f"Total number of result updates: {upd.modified_count}")

## Procedure updates

## Result updates
print("\nUpdating TorsionDrive Hashes:")

td_query = db.procedure.find({"procedure": "torsiondrive"}, limit=1000)
total = td_query.count()

updates = 0

# First update molecules
for raw_td in tqdm.tqdm(td_query, total=total):

tmpdata = raw_td.copy()
tmpdata.pop("_id")
tmpdata.pop("_cls")
tmpdata.pop("hash_index")
td = ptl.models.TorsionDriveRecord(**tmpdata)

upd = db.molecule.update_one({"_id": raw_td["_id"]}, {"$set": {"hash_index": td.hash_index}})
if upd.modified_count != 1:
print(upd)
print(upd_data)
break
else:
updates += 1

print("\nUpdating TorsionDriveDataset Fields:")

td_query = db.collection.find({"collection": "torsiondrivedataset"}, limit=1000)

for raw_col in td_query:

new_records = {}
for key, record in raw_col["records"].items():
tmp = record.copy()
tmp["object_map"] = tmp.pop("torsiondrives")
new_records[key] = tmp

db.collection.update_one({"_id": raw_col["_id"]}, {"records": new_records})


1 change: 1 addition & 0 deletions qcfractal/interface/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def list_collections(self, collection_type: Optional[str] = None, aslist: bool =
# Rename collection names
repl_name_map = collections_name_map()
for item in response:
item.pop("id", None)
if item["collection"] in repl_name_map:
item["collection"] = repl_name_map[item["collection"]]

Expand Down
7 changes: 6 additions & 1 deletion qcfractal/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ def __init__(self,
if storage_uri is None:
mongod_port = _find_port()
self._mongod_tmpdir = tempfile.TemporaryDirectory()

mongod_path = shutil.which("mongod")
if mongod_path is None:
raise OSError("Could not find `mongod` in PATH, please `conda install mongodb`.")

self._mongod_proc = _background_process(
[shutil.which("mongod"), f"--port={mongod_port}", f"--dbpath={self._mongod_tmpdir.name}"])
[mongod_path, f"--port={mongod_port}", f"--dbpath={self._mongod_tmpdir.name}"])
storage_uri = f"mongodb://localhost:{mongod_port}"
else:
self._mongod_tmpdir = None
Expand Down

0 comments on commit 5e464fb

Please sign in to comment.