Skip to content

Commit

Permalink
Remove unused code, add unit test for paddle wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
WardLT committed Dec 12, 2023
1 parent 2542052 commit 7bb250f
Show file tree
Hide file tree
Showing 17 changed files with 615 additions and 96 deletions.
106 changes: 17 additions & 89 deletions mofa/assemble.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Functions for assembling a MOF structure"""
from pathlib import Path
from typing import Sequence
from .model import NodeDescription, LigandDescription, MOFRecord
import os
import io
import itertools
Expand All @@ -9,6 +9,8 @@
import pymatgen.core as mg
from rdkit import Chem

from .model import NodeDescription, LigandDescription, MOFRecord


def readPillaredPaddleWheelXYZ(fpath, dummyElementCOO="At", dummyElementPillar="Fr"):
"""Read xyz file of a paddlewheel node
Expand Down Expand Up @@ -139,31 +141,6 @@ def rotmat2align(vec1, vec2):
return rotation_matrix


def assemble_COO_pcuMOF_multiProc(inputDict):
"""multiprocessing wrapper for assemble_COO_pcuMOF
Args:
inputDict: input of many structures to assemble in the format of dictionary
Returns:
returnValue a file path if assembly succeeded, None if failed
"""
nodePath = inputDict["nodePath"]
linkerPaths = inputDict["linkerPaths"]
newMOFdir = inputDict["newMOFdir"]
if "dummyElement" in inputDict.keys():
dummyElement = inputDict["dummyElement"]
else:
dummyElement = "At"

returnValue = None
try:
returnValue = assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFdir, dummyElement=dummyElement)
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
Expand Down Expand Up @@ -262,7 +239,7 @@ def assemble_COO_pcuMOF(nodePath, linkerPaths, newMOFpath, dummyElement="At"):
def assemble_pillaredPaddleWheel_pcuMOF(nodePath,
COOLinkerPaths,
PillarLinkerPath,
newMOFpath,
newMOFpath: Path,
dummyElementCOO="At",
dummyElementPillar="Fr"):
"""assembly code for -COO and -N ligands MOF with pcu topology
Expand All @@ -278,8 +255,12 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath,
Returns:
returnValue a cif file path if assembly succeeded, None if failed
"""
MOFRootdir = os.path.split(newMOFpath)[0]
os.makedirs(MOFRootdir, exist_ok=True)

# Ensure the output directory exists
MOFRootdir = newMOFpath.parent
MOFRootdir.mkdir(exist_ok=True, parents=True)

# Make sure the dummy atoms are valid elements
Chem.rdchem.Atom(dummyElementCOO).GetAtomicNum()
Chem.rdchem.Atom(dummyElementPillar).GetAtomicNum()

Expand Down Expand Up @@ -397,65 +378,6 @@ def assemble_pillaredPaddleWheel_pcuMOF(nodePath,
return ""


def assemble_PillarPaddle_pcuMOF_multiProc(inputDict):
"""multiprocessing wrapper for assemble_PillarPaddle_pcuMOF
Args:
inputDict: input of many structures to assemble in the format of dictionary
Returns:
returnValue a file path if assembly succeeded, None if failed
"""
nodePath = inputDict["nodePath"]
COOLinkerPaths = inputDict["COOLinkerPaths"]
PillarLinkerPath = inputDict["PillarLinkerPath"]
newMOFdir = inputDict["newMOFdir"]
if "dummyElementCOO" in inputDict.keys():
dummyElementCOO = inputDict["dummyElementCOO"]
else:
dummyElementCOO = "At"

if "dummyElementPillar" in inputDict.keys():
dummyElementPillar = inputDict["dummyElementPillar"]
else:
dummyElementPillar = "Fr"

returnValue = None
try:
returnValue = assemble_pillaredPaddleWheel_pcuMOF(nodePath,
COOLinkerPaths,
PillarLinkerPath,
newMOFdir,
dummyElementCOO=dummyElementCOO,
dummyElementPillar=dummyElementPillar)
except Exception as e:
print(e)
return returnValue


def testPillarMOF():
linker_base = "inferred_linkers/molGAN-batch512-Linkers"
linker_folders = os.listdir(linker_base)
# chosen_linker_folders
clf = [os.path.join(linker_base, x) for x in linker_folders[0:3]]
COOLinkers = [os.path.join(clf[0], y) for y in os.listdir(clf[0]) if y.endswith(".xyz") and y.startswith(
"linker-COO")] + [os.path.join(clf[1], y) for y in os.listdir(clf[1]) if y.endswith(".xyz") and y.startswith("linker-COO")]
PillarLinker = [os.path.join(clf[2], y) for y in os.listdir(clf[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("-"))))
newMOFdir = "newMOFs/molGAN-MOF-" + comb_name
return assemble_pillaredPaddleWheel_pcuMOF(nodePath,
COOLinkerPaths,
PillarLinkerPath,
newMOFdir)


def assemble_mof(nodes: Sequence[NodeDescription], ligands: Sequence[LigandDescription], topology: str) -> MOFRecord:
"""Generate a new MOF from the description of the nodes, ligands and toplogy
Expand All @@ -467,4 +389,10 @@ def assemble_mof(nodes: Sequence[NodeDescription], ligands: Sequence[LigandDescr
Returns:
A new MOF record
"""
raise NotImplementedError()

# Step 1: Detect which node type, use that to pick the assembly
if 'Zn' in nodes[0].xyz and topology == 'pcu':
# Step 2: Gather the XYZ files for the node and linker(s).
raise NotImplementedError() # Waiting on code from Xiaoli about how to go from "generated linker->ligands"
else:
raise NotImplementedError('No assembly methods for this linker/topology pair')
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
44

C 4.901243 2.336638 0.255723
C 3.650010 2.931033 0.312459
C 2.497499 2.160472 0.205546
C 2.565080 0.749789 0.081203
C 3.855778 0.144786 0.007902
C 3.949784 -1.252742 -0.095028
C 2.816533 -2.062186 -0.199978
C 3.013910 -3.554785 -0.337240
C 1.529574 -1.476919 -0.150841
C 0.372405 -2.279350 -0.198384
C -0.907093 -1.717370 -0.132282
C -2.018130 -2.556317 -0.040539
C -3.295936 -2.039968 0.175684
N -4.360885 -2.974602 0.419292
C -3.500453 -0.634928 0.130371
C -4.790414 -0.082290 0.283237
C -3.954492 2.119728 -0.214784
C -2.670487 1.604012 -0.435807
C -1.706776 2.518855 -1.157715
C -2.391276 0.235101 -0.117226
C -1.070394 -0.319715 -0.083930
C 0.084741 0.464237 0.110981
C 1.393144 -0.071253 0.009694
H 5.779871 2.968395 0.313287
H 3.571617 4.005618 0.420256
H 1.571617 2.709129 0.212835
H 4.913848 -1.738587 -0.075274
H 2.589446 -4.073511 0.547985
H 4.087453 -3.830979 -0.409272
H 2.515993 -3.918807 -1.260554
H 0.451933 -3.357237 -0.257575
H -1.880647 -3.632190 -0.046934
H -4.212204 -3.994420 0.248401
H -5.242556 -2.720449 0.911325
H -5.645107 -0.707010 0.480528
H -4.141038 3.171440 -0.401006
H -2.251735 3.157917 -1.885697
H -0.968398 1.947177 -1.756473
H -1.199336 3.191997 -0.435778
H -0.057639 1.472252 0.437153
C 5.027895 0.955912 0.069936
At 6.401478 0.425395 -0.091886
C -5.012517 1.292876 0.165861
At -6.368948 1.854212 0.372352
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
48

C 3.723864 1.399083 -3.865589
C 2.380070 1.743223 -3.810625
C 1.580353 1.300032 -2.759965
C 2.107879 0.477214 -1.732277
C 3.497398 0.165720 -1.772988
C 4.068675 -0.578564 -0.728860
C 3.309180 -1.020701 0.357016
C 4.007252 -1.798680 1.448527
C 1.919568 -0.752393 0.396335
C 1.119566 -1.249285 1.443829
C -0.257360 -1.003462 1.488884
C -1.027377 -1.612605 2.481396
C -2.416381 -1.488564 2.495522
N -3.143143 -2.167959 3.532177
C -3.055234 -0.664074 1.535999
C -4.461781 -0.594850 1.461838
C -5.088120 0.294604 0.592366
C -6.525855 0.345447 0.524010
N -7.729145 0.388597 0.467176
Fr -9.488540 0.452906 0.384586
C -4.326021 1.183446 -0.157649
C -2.925032 1.148189 -0.110059
C -2.209871 2.332423 -0.718075
C -2.268576 0.104025 0.621035
C -0.870963 -0.193406 0.511734
C -0.094380 0.183303 -0.602769
C 1.306894 -0.015571 -0.653748
C 4.294868 0.622172 -2.856115
C 5.704335 0.316569 -2.960187
N 6.879303 0.061382 -3.046429
Fr 8.596789 -0.313452 -3.168822
H 4.325850 1.754323 -4.693989
H 1.953896 2.366531 -4.586670
H 0.560163 1.645223 -2.769681
H 5.125755 -0.812433 -0.746022
H 3.846989 -1.302248 2.428744
H 3.611401 -2.835461 1.483477
H 5.104038 -1.859655 1.282885
H 1.553898 -1.858921 2.225765
H -0.547761 -2.231509 3.231899
H -2.669258 -2.889346 4.120692
H -4.094940 -1.873432 3.837675
H -5.091043 -1.244076 2.053666
H -4.827876 1.938532 -0.753618
H -2.091070 2.190944 -1.812470
H -2.800481 3.260793 -0.561213
H -1.229086 2.513160 -0.232126
H -0.611896 0.534729 -1.470698
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
64

C -4.452313 2.005762 2.102416
C -3.115032 2.239146 2.388190
C -2.116814 1.551197 1.704441
C -2.433532 0.621387 0.681922
C -3.809922 0.365237 0.413899
C -4.155789 -0.569210 -0.574896
C -3.186459 -1.288286 -1.277293
C -3.648435 -2.294063 -2.306738
C -1.814878 -1.044241 -1.028073
C -0.819219 -1.710987 -1.768655
C 0.540590 -1.469493 -1.543629
C 1.486119 -2.044798 -2.393064
C 2.837607 -1.713173 -2.297437
N 3.722492 -2.216690 -3.312532
C 3.287816 -0.915042 -1.212539
C 4.657693 -0.619068 -1.048692
C 4.221429 0.445987 1.065392
C 2.862577 0.117096 0.973464
C 2.066532 0.241515 2.253006
C 2.348057 -0.440333 -0.242820
C 0.950098 -0.595330 -0.518000
C -0.045475 0.175094 0.116001
C -1.428295 -0.076524 -0.061131
H -5.210722 2.543663 2.659207
H -2.847869 2.951341 3.158747
H -1.108271 1.759997 2.018200
H -5.195584 -0.748589 -0.812967
H -4.754659 -2.392858 -2.328768
H -3.316871 -1.976793 -3.317857
H -3.230209 -3.295589 -2.071563
H -1.090006 -2.406407 -2.552789
H 1.159917 -2.691071 -3.200806
H 3.393464 -2.953530 -3.976170
H 4.640097 -1.778976 -3.537087
H 5.396246 -0.967875 -1.751778
H 4.588033 0.941348 1.957341
H 1.695204 1.280127 2.376985
H 2.706324 0.007990 3.131438
H 1.231756 -0.488084 2.289504
H 0.273991 1.034049 0.667160
C -4.818075 1.061513 1.138200
C -6.264050 0.813457 0.937931
C -7.087162 1.823699 0.416534
C -8.455722 1.596506 0.243297
N -9.012630 0.362338 0.596699
Fr -10.764493 0.072456 0.372813
C -8.198807 -0.643720 1.129125
C -6.830017 -0.418552 1.304302
C 5.120503 0.102470 0.055229
C 6.563487 0.432338 0.184251
C 7.232096 0.268151 1.412024
C 8.590280 0.579567 1.526173
N 9.296445 1.058436 0.418604
Fr 11.034940 1.456745 0.568010
C 8.642605 1.223744 -0.806106
C 7.284835 0.912387 -0.924656
H -6.667490 2.782955 0.139636
H -9.080800 2.380139 -0.165494
H -8.625220 -1.598807 1.408584
H -6.210042 -1.201978 1.723168
H 6.709882 -0.117961 2.278276
H 9.092846 0.444795 2.475600
H 9.183889 1.596289 -1.666532
H 6.794236 1.061221 -1.878621
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
17

C 0.069719 -1.558622 -0.045561
C 0.932503 0.700713 0.199745
C 2.047116 1.691189 0.420054
C -0.361038 1.194011 -0.037610
C -1.212739 -1.062715 -0.315689
N -2.245718 -1.991843 -0.673625
H 0.224758 -2.631135 -0.055158
H 2.318132 1.718034 1.496039
H 2.933283 1.415156 -0.189166
H 1.748836 2.716781 0.114334
H -0.530923 2.264504 -0.017763
H -2.090769 -3.019780 -0.571568
H -3.112146 -1.691951 -1.170050
C 1.148173 -0.700148 0.230242
At 2.472338 -1.303982 0.533859
C -1.442098 0.332068 -0.277295
At -2.788373 0.926369 -0.444685
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
21

C 0.994485 1.078221 -0.296693
C -0.338074 1.075137 -0.727444
C -0.825966 2.200646 -1.488337
N -1.234682 3.139981 -2.123614
Fr -1.833475 4.513038 -3.052059
C -1.176153 -0.015514 -0.415321
C -2.613235 -0.044941 -0.865839
C -0.657688 -1.088525 0.327318
C 0.675531 -1.084568 0.757779
C 1.161953 -2.209839 1.518009
N 1.566989 -3.150977 2.153176
Fr 2.159582 -4.526750 3.081644
C 1.511784 0.006782 0.444823
N 2.881642 0.045023 0.868841
H 1.635099 1.918721 -0.538828
H -3.156785 0.825021 -0.440792
H -3.129244 -0.971636 -0.535934
H -2.659148 0.002104 -1.974267
H -1.293682 -1.931914 0.572472
H 3.488814 0.860461 0.629302
H 3.310035 -0.729181 1.422329
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
37

C 0.668103 1.203568 -0.488988
C -0.732920 1.128634 -0.509704
C -1.516754 2.316676 -1.004728
C -0.589997 -1.135864 0.367349
C 0.809564 -1.070585 0.359384
N 1.560510 -2.233104 0.736833
H 1.158695 2.116426 -0.807917
H -0.901593 2.946096 -1.682662
H -2.408475 1.988819 -1.579222
H -1.838499 2.937223 -0.143041
H -1.076416 -2.045633 0.700089
H 2.593086 -2.293023 0.601157
H 1.074032 -3.085586 1.093938
C 1.447287 0.121355 -0.051556
C 2.918977 0.274819 -0.015714
C 3.619701 0.132866 1.193841
C 5.007332 0.299863 1.228403
N 5.705040 0.618676 0.058423
Fr 7.481395 0.832621 0.104463
C 5.011675 0.774441 -1.146729
C 3.623973 0.607776 -1.184119
C -1.370434 -0.045147 -0.044608
C -2.844967 -0.168015 0.010564
C -3.603605 0.701277 0.811891
C -4.994681 0.573726 0.868700
N -5.638215 -0.427325 0.133150
Fr -7.419093 -0.589479 0.207375
C -4.887288 -1.303832 -0.657526
C -3.496026 -1.178361 -0.716073
H 3.090428 -0.103042 2.108985
H 5.537655 0.184106 2.165105
H 5.545788 1.024797 -2.054539
H 3.099804 0.730481 -2.124053
H -3.117724 1.469374 1.400399
H -5.569745 1.250105 1.488270
H -5.379358 -2.082608 -1.226242
H -2.926796 -1.862264 -1.333759
Loading

0 comments on commit 7bb250f

Please sign in to comment.