From dafe00a6b4744d9d2c38f50e829eff3a83eae664 Mon Sep 17 00:00:00 2001 From: doublylinkedlist Date: Fri, 8 Dec 2023 09:22:03 -0600 Subject: [PATCH] Update assemble.py --- mofa/assemble.py | 204 ++++++++++++++++++++++++----------------------- 1 file changed, 106 insertions(+), 98 deletions(-) diff --git a/mofa/assemble.py b/mofa/assemble.py index b8eca115..da6a2115 100644 --- a/mofa/assemble.py +++ b/mofa/assemble.py @@ -9,6 +9,7 @@ import pymatgen.core as mg from rdkit import Chem + def readPillaredPaddleWheelXYZ(fpath, dummyElementCOO="At", dummyElementPillar="Fr"): """Read xyz file of a paddlewheel node @@ -21,22 +22,22 @@ def readPillaredPaddleWheelXYZ(fpath, dummyElementCOO="At", dummyElementPillar=" Pandas of node [element, x, y, z], -COO anchor ID pairs in the opposite directions, -N anchor ID pairs in the opposite directions """ df = pd.read_csv(fpath, sep=r"\s+", skiprows=2, names=["el", "x", "y", "z"]) - COOAnchorIds = df[df["el"]==dummyElementCOO].index.tolist() - PillarAnchorIds = df[df["el"]==dummyElementPillar].index.tolist() + COOAnchorIds = df[df["el"] == dummyElementCOO].index.tolist() + PillarAnchorIds = df[df["el"] == dummyElementPillar].index.tolist() df["maxDist"] = 0. anchorPairs = [] while len(COOAnchorIds) > 0: - maxDist = 0 currAnchor = COOAnchorIds[-1] COOAnchorIds = COOAnchorIds[:-1] - df.loc[COOAnchorIds, "maxDist"] = np.linalg.norm(df.loc[currAnchor, ["x", "y", "z"]].astype(float).values - \ + df.loc[COOAnchorIds, "maxDist"] = np.linalg.norm(df.loc[currAnchor, ["x", "y", "z"]].astype(float).values - df.loc[COOAnchorIds, ["x", "y", "z"]].values, axis=1) pairAnchor = df[df["maxDist"] == df.loc[COOAnchorIds, "maxDist"].max()].index[0] - COOAnchorIds = COOAnchorIds[:COOAnchorIds.index(pairAnchor)] + COOAnchorIds[COOAnchorIds.index(pairAnchor)+1:] + COOAnchorIds = COOAnchorIds[:COOAnchorIds.index(pairAnchor)] + COOAnchorIds[COOAnchorIds.index(pairAnchor) + 1:] anchorPairs.append([currAnchor, pairAnchor]) return df[["el", "x", "y", "z"]], anchorPairs, PillarAnchorIds + def readTetramerXYZ(fpath, dummyElement="At"): """Read xyz file of a tetramer node @@ -48,22 +49,22 @@ def readTetramerXYZ(fpath, dummyElement="At"): Pandas of node element, x, y, z, and anchor ID pairs """ df = pd.read_csv(fpath, sep=r"\s+", skiprows=2, names=["el", "x", "y", "z"]) - anchorIds = df[df["el"]==dummyElement].index.tolist() + anchorIds = df[df["el"] == dummyElement].index.tolist() df["maxDist"] = 0. anchorPairs = [] while len(anchorIds) > 0: - maxDist = 0 currAnchor = anchorIds[-1] anchorIds = anchorIds[:-1] - df.loc[anchorIds, "maxDist"] = np.linalg.norm(df.loc[currAnchor, ["x", "y", "z"]].astype(float).values - \ + df.loc[anchorIds, "maxDist"] = np.linalg.norm(df.loc[currAnchor, ["x", "y", "z"]].astype(float).values - df.loc[anchorIds, ["x", "y", "z"]].values, axis=1) pairAnchor = df[df["maxDist"] == df.loc[anchorIds, "maxDist"].max()].index[0] - anchorIds = anchorIds[:anchorIds.index(pairAnchor)] + anchorIds[anchorIds.index(pairAnchor)+1:] + anchorIds = anchorIds[:anchorIds.index(pairAnchor)] + anchorIds[anchorIds.index(pairAnchor) + 1:] anchorPairs.append([currAnchor, pairAnchor]) - + return df[["el", "x", "y", "z"]], anchorPairs + def readCOOLinkerXYZ(fpath, dummyElement="At"): """Read xyz file of a -COO type connect-2 ligand @@ -75,9 +76,10 @@ def readCOOLinkerXYZ(fpath, dummyElement="At"): Pandas of node element, x, y, z, and anchor ID pairs """ df = pd.read_csv(fpath, sep=r"\s+", skiprows=2, names=["el", "x", "y", "z"]) - anchorIds = df[df["el"]==dummyElement].index.tolist() + anchorIds = df[df["el"] == dummyElement].index.tolist() return df, anchorIds + def readNbasedLinkerXYZ(fpath, dummyElement="Fr"): """Read xyz file of a -N type connect-2 ligand @@ -89,11 +91,12 @@ def readNbasedLinkerXYZ(fpath, dummyElement="Fr"): Pandas of node element, x, y, z, and anchor ID pairs """ df = pd.read_csv(fpath, sep=r"\s+", skiprows=2, names=["el", "x", "y", "z"]) - anchorIds = df[df["el"]==dummyElement].index.tolist() + anchorIds = df[df["el"] == dummyElement].index.tolist() return df, anchorIds + def pandas2xyzfile(df, fpath, useStringIO=False): - """write a Pandas with [element, x, y, z] to a xyz file + """write a Pandas with [element, x, y, z] to a xyz file Args: df: Pandas with [element, x, y, z] @@ -110,6 +113,7 @@ def pandas2xyzfile(df, fpath, useStringIO=False): wf.write(str(len(df)) + "\n\n" + df.to_string(header=None, index=None)) return "" + def rotmat2align(vec1, vec2): """return a rotation matrix that rotates a 3D vector to align with another 3D vector @@ -134,6 +138,7 @@ def rotmat2align(vec1, vec2): rotation_matrix = np.eye(3) + kmat + kmat.dot(kmat) * ((1 - c) / (s ** 2)) return rotation_matrix + def assemble_COO_pcuMOF_multiProc(inputDict): """multiprocessing wrapper for assemble_COO_pcuMOF @@ -154,17 +159,18 @@ def assemble_COO_pcuMOF_multiProc(inputDict): returnValue = None try: returnValue = assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFdir, dummyElement=dummyElement) - except Exception as e: + except Exception as e: print(e) return returnValue + def assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFpath, dummyElement="At"): """assembly code for -COO only MOF with pcu topology Args: - nodePath: node xyz file path, - linkerPaths: node xyz file paths, - newMOFpath: assembled MOF file path, + nodePath: node xyz file path, + linkerPaths: node xyz file paths, + newMOFpath: assembled MOF file path, dummyElement: dummy element for anchoring positions Returns: @@ -172,8 +178,8 @@ def assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFpath, dummyElement="At"): """ MOFRootdir = os.path.split(newMOFpath)[0] os.makedirs(MOFRootdir, exist_ok=True) - dummyAtomicNum = Chem.rdchem.Atom(dummyElement).GetAtomicNum() - + Chem.rdchem.Atom(dummyElement).GetAtomicNum() + node_df, nodeAnchors = readTetramerXYZ(nodePath) linkerAnchors = [None for x in range(3)] linker_dfs = [None for x in range(3)] @@ -192,16 +198,16 @@ def assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFpath, dummyElement="At"): # translate to align n1 and l1 linkerAnchor1POS = linker_df.loc[linkerAnchorPair[0], ["x", "y", "z"]].astype(float).values - linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS) * \ - (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS), + linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS) * + (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS), axis=1) - linkerCarbon1Idx = linker_df[linker_df["dist2"]==linker_df[linker_df["el"]=="C"]["dist2"].min()].index.tolist()[0] + linkerCarbon1Idx = linker_df[linker_df["dist2"] == linker_df[linker_df["el"] == "C"]["dist2"].min()].index.tolist()[0] linkerAnchor2POS = linker_df.loc[linkerAnchorPair[1], ["x", "y", "z"]].astype(float).values - linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS) * \ - (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS), + linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS) * + (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS), axis=1) - linkerCarbon2Idx = linker_df[linker_df["dist2"]==linker_df[linker_df["el"]=="C"]["dist2"].min()].index.tolist()[0] + linkerCarbon2Idx = linker_df[linker_df["dist2"] == linker_df[linker_df["el"] == "C"]["dist2"].min()].index.tolist()[0] linkerAnchorVec = linkerAnchor1POS - linkerAnchor2POS @@ -209,31 +215,30 @@ def assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFpath, dummyElement="At"): linker_df.loc[:, ["x", "y", "z"]] = rotmat.dot(linker_df.loc[:, ["x", "y", "z"]].values.T).T displacementVec = node_df.loc[noderAnchorPair[0], ["x", "y", "z"]].astype(float).values - \ - linker_df.loc[linkerCarbon1Idx, ["x", "y", "z"]].astype(float).values + linker_df.loc[linkerCarbon1Idx, ["x", "y", "z"]].astype(float).values linker_df.loc[:, ["x", "y", "z"]] = linker_df.loc[:, ["x", "y", "z"]].values + displacementVec - ldf.append(linker_df[linker_df["el"]!=dummyElement].copy(deep=True)) + ldf.append(linker_df[linker_df["el"] != dummyElement].copy(deep=True)) farAnchorNLPairDispVec = node_df.loc[noderAnchorPair[1], ["x", "y", "z"]].astype(float).values - \ - linker_df.loc[linkerCarbon2Idx, ["x", "y", "z"]].astype(float).values + linker_df.loc[linkerCarbon2Idx, ["x", "y", "z"]].astype(float).values latVec.append(farAnchorNLPairDispVec) - #pandas2xyzfile(linker_df, os.path.join(newMOFdir, "linker-"+str(_i_)+".xyz")) + # pandas2xyzfile(linker_df, os.path.join(newMOFdir, "linker-"+str(_i_)+".xyz")) - - #pandas2xyzfile(node_df, os.path.join(newMOFpath, "node.xyz")) - final_df = pd.concat(ldf + [node_df[node_df["el"]!=dummyElement].copy(deep=True)], axis=0) - final_df = final_df[final_df["el"]!=dummyElement].reset_index(drop=True)[["el", "x", "y", "z"]] + # pandas2xyzfile(node_df, os.path.join(newMOFpath, "node.xyz")) + final_df = pd.concat(ldf + [node_df[node_df["el"] != dummyElement].copy(deep=True)], axis=0) + final_df = final_df[final_df["el"] != dummyElement].reset_index(drop=True)[["el", "x", "y", "z"]] xyzstr = pandas2xyzfile(final_df, os.path.join(MOFRootdir, "mofCart.xyz"), useStringIO=True) - + mol = mg.Molecule.from_str(xyzstr, fmt="xyz") # try: # os.remove(os.path.join(MOFRootdir, "mofCart.xyz")) # except: # print(os.path.join(MOFRootdir, "mofCart.xyz") + " does not exist!\n") - MOFstruct = mg.Structure(np.array(latVec), - mol.species, - mol.cart_coords, - coords_are_cartesian=True) - + MOFstruct = mg.Structure(np.array(latVec), + mol.species, + mol.cart_coords, + coords_are_cartesian=True) + df = pd.read_csv("../xyan11-code/OChemDB_bond_threshold.csv", index_col=0) element2bondLengthMap = dict(zip(df["element"], df["min"] - (df["stddev"] * 0.01))) unique_bond_el = list(set(list(itertools.chain(*[["-".join(sorted([x.symbol, y.symbol])) for x in MOFstruct.species] for y in MOFstruct.species])))) @@ -242,10 +247,10 @@ def assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFpath, dummyElement="At"): if x not in element2bondLengthMap: element2bondLengthMap[x] = 0. for y in x.split("-"): - if type(mg.periodic_table.Element(y).atomic_radius_calculated) != type(None): + if not isinstance(mg.periodic_table.Element(y).atomic_radius_calculated, type(None)): element2bondLengthMap[x] = element2bondLengthMap[x] + mg.periodic_table.Element(y).atomic_radius_calculated distMat = MOFstruct.distance_matrix - distMat[distMat==0] = np.inf + distMat[distMat == 0] = np.inf bondLengthThresMat = np.array([[element2bondLengthMap["-".join(sorted([x.symbol, y.symbol]))] for x in MOFstruct.species] for y in MOFstruct.species]) if np.all(distMat > bondLengthThresMat): MOFstruct.to(filename=newMOFpath + ".cif", fmt="cif") @@ -253,20 +258,21 @@ def assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFpath, dummyElement="At"): else: return "" -def assemble_pillaredPaddleWheel_pcuMOF(nodePath, - COOLinkerPaths, - PillarLinkerPath, - newMOFpath, - dummyElementCOO="At", + +def assemble_pillaredPaddleWheel_pcuMOF(nodePath, + COOLinkerPaths, + PillarLinkerPath, + newMOFpath, + dummyElementCOO="At", dummyElementPillar="Fr"): """assembly code for -COO and -N ligands MOF with pcu topology Args: - nodePath: node xyz file path, - COOLinkerPaths: -COO node xyz file paths, - PillarLinkerPath: -N node xyz file paths, - newMOFpath: assembled MOF file path, - dummyElementCOO: dummy element for -COO anchoring positions, + nodePath: node xyz file path, + COOLinkerPaths: -COO node xyz file paths, + PillarLinkerPath: -N node xyz file paths, + newMOFpath: assembled MOF file path, + dummyElementCOO: dummy element for -COO anchoring positions, dummyElementPillar: dummy element for -N anchoring positions Returns: @@ -274,8 +280,8 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath, """ MOFRootdir = os.path.split(newMOFpath)[0] os.makedirs(MOFRootdir, exist_ok=True) - dummyAtomicNumCOO = Chem.rdchem.Atom(dummyElementCOO).GetAtomicNum() - dummyAtomicNumPillar = Chem.rdchem.Atom(dummyElementPillar).GetAtomicNum() + Chem.rdchem.Atom(dummyElementCOO).GetAtomicNum() + Chem.rdchem.Atom(dummyElementPillar).GetAtomicNum() node_df, nodeAnchorsCOO, nodeAnchorsPillar = readPillaredPaddleWheelXYZ(nodePath) @@ -296,16 +302,16 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath, # translate to align n1 and l1 linkerAnchor1POS = linker_df.loc[linkerAnchorPair[0], ["x", "y", "z"]].astype(float).values - linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS) * \ - (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS), + linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS) * + (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS), axis=1) - linkerNitrogen1Idx = linker_df[linker_df["dist2"]==linker_df[linker_df["el"]=="N"]["dist2"].min()].index.tolist()[0] + linkerNitrogen1Idx = linker_df[linker_df["dist2"] == linker_df[linker_df["el"] == "N"]["dist2"].min()].index.tolist()[0] linkerAnchor2POS = linker_df.loc[linkerAnchorPair[1], ["x", "y", "z"]].astype(float).values - linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS) * \ - (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS), + linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS) * + (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS), axis=1) - linkerNitrogen2Idx = linker_df[linker_df["dist2"]==linker_df[linker_df["el"]=="N"]["dist2"].min()].index.tolist()[0] + linkerNitrogen2Idx = linker_df[linker_df["dist2"] == linker_df[linker_df["el"] == "N"]["dist2"].min()].index.tolist()[0] linkerAnchorVec = linkerAnchor1POS - linkerAnchor2POS @@ -313,12 +319,12 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath, linker_df.loc[:, ["x", "y", "z"]] = rotmat.dot(linker_df.loc[:, ["x", "y", "z"]].values.T).T displacementVec = node_df.loc[noderAnchorPair[0], ["x", "y", "z"]].astype(float).values - \ - linker_df.loc[linkerNitrogen1Idx, ["x", "y", "z"]].astype(float).values + linker_df.loc[linkerNitrogen1Idx, ["x", "y", "z"]].astype(float).values linker_df.loc[:, ["x", "y", "z"]] = linker_df.loc[:, ["x", "y", "z"]].values + displacementVec - ldf.append(linker_df[linker_df["el"]!=dummyElementPillar].copy(deep=True)) + ldf.append(linker_df[linker_df["el"] != dummyElementPillar].copy(deep=True)) farAnchorNLPairDispVec = node_df.loc[noderAnchorPair[1], ["x", "y", "z"]].astype(float).values - \ - linker_df.loc[linkerNitrogen2Idx, ["x", "y", "z"]].astype(float).values + linker_df.loc[linkerNitrogen2Idx, ["x", "y", "z"]].astype(float).values latVec.append(farAnchorNLPairDispVec) for _i_ in range(len(nodeAnchorsCOO)): @@ -331,16 +337,16 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath, # translate to align n1 and l1 linkerAnchor1POS = linker_df.loc[linkerAnchorPair[0], ["x", "y", "z"]].astype(float).values - linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS) * \ - (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS), + linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS) * + (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor1POS), axis=1) - linkerCarbon1Idx = linker_df[linker_df["dist2"]==linker_df[linker_df["el"]=="C"]["dist2"].min()].index.tolist()[0] + linkerCarbon1Idx = linker_df[linker_df["dist2"] == linker_df[linker_df["el"] == "C"]["dist2"].min()].index.tolist()[0] linkerAnchor2POS = linker_df.loc[linkerAnchorPair[1], ["x", "y", "z"]].astype(float).values - linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS) * \ - (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS), + linker_df["dist2"] = np.sum((linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS) * + (linker_df.loc[:, ["x", "y", "z"]].astype(float).values - linkerAnchor2POS), axis=1) - linkerCarbon2Idx = linker_df[linker_df["dist2"]==linker_df[linker_df["el"]=="C"]["dist2"].min()].index.tolist()[0] + linkerCarbon2Idx = linker_df[linker_df["dist2"] == linker_df[linker_df["el"] == "C"]["dist2"].min()].index.tolist()[0] linkerAnchorVec = linkerAnchor1POS - linkerAnchor2POS @@ -348,30 +354,29 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath, linker_df.loc[:, ["x", "y", "z"]] = rotmat.dot(linker_df.loc[:, ["x", "y", "z"]].values.T).T displacementVec = node_df.loc[noderAnchorPair[0], ["x", "y", "z"]].astype(float).values - \ - linker_df.loc[linkerCarbon1Idx, ["x", "y", "z"]].astype(float).values + linker_df.loc[linkerCarbon1Idx, ["x", "y", "z"]].astype(float).values linker_df.loc[:, ["x", "y", "z"]] = linker_df.loc[:, ["x", "y", "z"]].values + displacementVec - ldf.append(linker_df[linker_df["el"]!=dummyElementCOO].copy(deep=True)) + ldf.append(linker_df[linker_df["el"] != dummyElementCOO].copy(deep=True)) farAnchorNLPairDispVec = node_df.loc[noderAnchorPair[1], ["x", "y", "z"]].astype(float).values - \ - linker_df.loc[linkerCarbon2Idx, ["x", "y", "z"]].astype(float).values + linker_df.loc[linkerCarbon2Idx, ["x", "y", "z"]].astype(float).values latVec.append(farAnchorNLPairDispVec) - - #pandas2xyzfile(node_df, os.path.join(newMOFpath, "node.xyz")) - final_df = pd.concat(ldf + [node_df[(node_df["el"]!=dummyElementCOO)&(node_df["el"]!=dummyElementPillar)].copy(deep=True)], axis=0) - final_df = final_df[final_df["el"]!=dummyElementCOO].reset_index(drop=True)[["el", "x", "y", "z"]] + # pandas2xyzfile(node_df, os.path.join(newMOFpath, "node.xyz")) + final_df = pd.concat(ldf + [node_df[(node_df["el"] != dummyElementCOO) & (node_df["el"] != dummyElementPillar)].copy(deep=True)], axis=0) + final_df = final_df[final_df["el"] != dummyElementCOO].reset_index(drop=True)[["el", "x", "y", "z"]] xyzstr = pandas2xyzfile(final_df, os.path.join(MOFRootdir, "mofCart.xyz"), useStringIO=True) - + mol = mg.Molecule.from_str(xyzstr, fmt="xyz") # try: # os.remove(os.path.join(MOFRootdir, "mofCart.xyz")) # except: # print(os.path.join(MOFRootdir, "mofCart.xyz") + " does not exist!\n") - MOFstruct = mg.Structure(np.array(latVec), - mol.species, - mol.cart_coords, - coords_are_cartesian=True) - + MOFstruct = mg.Structure(np.array(latVec), + mol.species, + mol.cart_coords, + coords_are_cartesian=True) + df = pd.read_csv("../xyan11-code/OChemDB_bond_threshold.csv", index_col=0) element2bondLengthMap = dict(zip(df["element"], df["min"] - (df["stddev"] * 0.01))) unique_bond_el = list(set(list(itertools.chain(*[["-".join(sorted([x.symbol, y.symbol])) for x in MOFstruct.species] for y in MOFstruct.species])))) @@ -380,10 +385,10 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath, if x not in element2bondLengthMap: element2bondLengthMap[x] = 0. for y in x.split("-"): - if type(mg.periodic_table.Element(y).atomic_radius_calculated) != type(None): + if not isinstance(mg.periodic_table.Element(y).atomic_radius_calculated, type(None)): element2bondLengthMap[x] = element2bondLengthMap[x] + mg.periodic_table.Element(y).atomic_radius_calculated distMat = MOFstruct.distance_matrix - distMat[distMat==0] = np.inf + distMat[distMat == 0] = np.inf bondLengthThresMat = np.array([[element2bondLengthMap["-".join(sorted([x.symbol, y.symbol]))] for x in MOFstruct.species] for y in MOFstruct.species]) if np.all(distMat > bondLengthThresMat): MOFstruct.to(filename=newMOFpath + ".cif", fmt="cif") @@ -391,6 +396,7 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath, else: return "" + def assemble_PillarPaddle_pcuMOF_multiProc(inputDict): """multiprocessing wrapper for assemble_PillarPaddle_pcuMOF @@ -416,35 +422,37 @@ def assemble_PillarPaddle_pcuMOF_multiProc(inputDict): returnValue = None try: - returnValue = assemble_pillaredPaddleWheel_pcuMOF(nodePath, - COOLinkerPaths, - PillarLinkerPath, - newMOFdir, - dummyElementCOO=dummyElementCOO, - dummyElementPillar=dummyElementPillar) - except Exception as e: + returnValue = assemble_pillaredPaddleWheel_pcuMOF(nodePath, + COOLinkerPaths, + PillarLinkerPath, + newMOFdir, + dummyElementCOO=dummyElementCOO, + dummyElementPillar=dummyElementPillar) + except Exception as e: print(e) return returnValue + def testPillarMOF(): - import os, io linker_base = "inferred_linkers/molGAN-batch512-Linkers" linker_folders = os.listdir(linker_base) chosen_linker_folders = [os.path.join(linker_base, x) for x in linker_folders[0:3]] - COOLinkers = [os.path.join(chosen_linker_folders[0], y) for y in os.listdir(chosen_linker_folders[0]) if y.endswith(".xyz") and y.startswith("linker-COO")] + [os.path.join(chosen_linker_folders[1], y) for y in os.listdir(chosen_linker_folders[1]) if y.endswith(".xyz") and y.startswith("linker-COO")] - PillarLinker = [os.path.join(chosen_linker_folders[2], y) for y in os.listdir(chosen_linker_folders[2]) if y.endswith(".xyz") and y.startswith("linker-") and "COO" not in y][0] + COOLinkers = [os.path.join(chosen_linker_folders[0], y) for y in os.listdir(chosen_linker_folders[0]) if y.endswith(".xyz") and y.startswith( + "linker-COO")] + [os.path.join(chosen_linker_folders[1], y) for y in os.listdir(chosen_linker_folders[1]) if y.endswith(".xyz") and y.startswith("linker-COO")] + PillarLinker = [os.path.join(chosen_linker_folders[2], y) for y in os.listdir(chosen_linker_folders[2]) + if y.endswith(".xyz") and y.startswith("linker-") and "COO" not in y][0] nodePath = "nodes/zinc_paddle_pillar.xyz" COOLinkerPaths = COOLinkers PillarLinkerPath = PillarLinker comb_name = "L" + "".join(list(reversed(os.path.split(COOLinkers[0])[-1].replace(".xyz", "").replace("linker-", "").split("-")))) + "-" + \ - "L" + "".join(list(reversed(os.path.split(COOLinkers[1])[-1].replace(".xyz", "").replace("linker-", "").split("-")))) + "-" + \ - "L" + "".join(list(reversed(os.path.split(PillarLinker)[-1].replace(".xyz", "").replace("linker-", "").split("-")))) + "L" + "".join(list(reversed(os.path.split(COOLinkers[1])[-1].replace(".xyz", "").replace("linker-", "").split("-")))) + "-" + \ + "L" + "".join(list(reversed(os.path.split(PillarLinker)[-1].replace(".xyz", "").replace("linker-", "").split("-")))) newMOFdir = "newMOFs/molGAN-MOF-" + comb_name - return assemble_pillaredPaddleWheel_pcuMOF(nodePath, - COOLinkerPaths, - PillarLinkerPath, + return assemble_pillaredPaddleWheel_pcuMOF(nodePath, + COOLinkerPaths, + PillarLinkerPath, newMOFdir)