Skip to content

Commit

Permalink
Merge pull request #37 from dcheng2022/master
Browse files Browse the repository at this point in the history
Merge MOFid 2024
  • Loading branch information
KunhuanLiu authored Aug 28, 2024
2 parents b3f06c2 + 79e2668 commit 799c50c
Show file tree
Hide file tree
Showing 38,453 changed files with 6,594,329 additions and 119,355 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .dockerignore
bin/
openbabel/build
openbabel/installed
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ openbabel/data/* text eol=lf
openbabel/data/*.png binary
Makefile text eol=lf
*.sh text eol=lf

# Apply spabs filter
*.py filter=spabs
44 changes: 44 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: run_tests
on:
push:
paths:
- "**.py"
- "Makefile"
- "openbabel/**"
- "eigen/**"
- "src/**"
pull_request:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install colordiff
run: |
sudo apt-get update
sudo apt-get install colordiff
- name: Build Project
run: |
mkdir Output
make test
- name: Run Unit Tests
run: make unittest
- name: Run Intermediate Tests
run : make intermediatetest
- name: Archive Mismatch Artifacts
uses: actions/upload-artifact@v4
with:
name: mismatch
path: Mismatch
if-no-files-found: ignore
retention-days: 1
- name: Run Integration Tests
run: |
python set_paths.py
pip install .
make pytest
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Mismatch/
.venv/
venv/
.env/
env/
*.pyc
Data/
!README.md
Expand Down
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

44 changes: 22 additions & 22 deletions Analysis/extract_carbon_mofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
DEST_DIR = 'Summary/OrigCore/'

if not os.path.isdir(DEST_DIR):
print('Moving original CoRE MOF files to a new directory: ' + DEST_DIR)
os.mkdir(DEST_DIR)
core_files = glob.glob('Summary/core*')
for core_output in core_files:
shutil.move(core_output, DEST_DIR)
print('Moving original CoRE MOF files to a new directory: ' + DEST_DIR)
os.mkdir(DEST_DIR)
core_files = glob.glob('Summary/core*')
for core_output in core_files:
shutil.move(core_output, DEST_DIR)

def read_file(data_file):
with open(os.path.join('Summary/OrigCore/', data_file), 'r') as f:
data_contents = f.readlines()
# Let's keep the newlines so we don't have to rewrite them later:
#data_contents = [x.strip('\n') for x in data_contents]
return data_contents
with open(os.path.join('Summary/OrigCore/', data_file), 'r') as f:
data_contents = f.readlines()
# Let's keep the newlines so we don't have to rewrite them later:
#data_contents = [x.strip('\n') for x in data_contents]
return data_contents

mofids = read_file('core_mofid.smi')
#smis = read_file('core.smi')
Expand All @@ -37,18 +37,18 @@ def read_file(data_file):

# Map the input to output files line-by-line
for lineno in range(len(elements)):
cif_name = elements[lineno].split()[0]
assert cif_name.endswith('.cif') or cif_name.endswith('.CIF')
cif_name = cif_name[:-4]
# Check that our lines are properly aligned between all of the MOFid code output files
assert mofids[lineno].endswith(';' + cif_name + '\n')
assert mofkeys[lineno].startswith(cif_name + '.cif\t')

contains_carbon = re.search(r'[ \t]C ', elements[lineno])
if contains_carbon:
out_mofids.write(mofids[lineno])
out_mofkeys.write(mofkeys[lineno])
out_files.write(cif_name + '\n')
cif_name = elements[lineno].split()[0]
assert cif_name.endswith('.cif') or cif_name.endswith('.CIF')
cif_name = cif_name[:-4]
# Check that our lines are properly aligned between all of the MOFid code output files
assert mofids[lineno].endswith(';' + cif_name + '\n')
assert mofkeys[lineno].startswith(cif_name + '.cif\t')

contains_carbon = re.search(r'[ \t]C ', elements[lineno])
if contains_carbon:
out_mofids.write(mofids[lineno])
out_mofkeys.write(mofkeys[lineno])
out_files.write(cif_name + '\n')

out_mofids.close()
out_mofkeys.close()
Expand Down
30 changes: 9 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
FROM continuumio/miniconda3
# MOFid 2024
FROM python:3.11-bookworm

# set up conda and deps, per .travis.yml
RUN apt-get update -qq
RUN mkdir -p /usr/share/man/man1/ # required to prevent default-jre installation from crashing
RUN apt-get install -qq default-jre
RUN apt-get install -qq build-essential cmake
LABEL AUTHOR="[email protected]"
LABEL version="2024"

RUN conda config --set always_yes yes --set changeps1 no
RUN conda create -q -n py2 python=2.7

# copy source code from git
WORKDIR /mofid
COPY . /mofid

# compile openbabel, C++ analysis code, and Python package
RUN make init
RUN python set_paths.py
RUN pip install .
# Disabling conda environment for now and keeping with base Python
#RUN source activate py2
#RUN pip install .
#RUN conda deactivate

# then run the code, either interactively or via docker command line

RUN apt-get update -qq \
&& apt-get install -qq default-jre gcc-11 g++-11 cmake \
&& make init \
&& python set_paths.py \
&& pip install . \
62 changes: 50 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.PHONY: all backup test diff ob_changes.patch init eclipse web init-web github-web html one exe btc
.PHONY: all backup test unittest intermediatetest pytest diff ob_changes.patch init debug eclipse web init-web github-web html one exe btc

mofid-dir := $(shell pwd)
python-packages-dir := $(shell python -m site | grep -o "/.*/site-packages" | head --lines 1)

all:
@echo "Sample make file for experimentation. Still needs work. Only backup implemented"
Expand All @@ -17,11 +20,11 @@ bin/tsfm_smiles: src/tsfm_smiles.cpp openbabel/build/lib/cifformat.so
cd bin && make tsfm_smiles

exe:
cd bin && make
cd bin && make -j$$(nproc)

one:
cd bin && make; \
cd ..; \
cd $(mofid-dir); \
bin/sbu Resources/TestCIFs/P1-IRMOF-1.cif

btc:
Expand All @@ -40,23 +43,58 @@ ob_changes.patch:
git diff --no-prefix 7810ca7bb1beef14b2a62cf5bad3a8551b187824 -- openbabel/*.cpp openbabel/*.h ':!openbabel/data/*' ':!openbabel/test/*' > $@
# Lists my changes to the main OpenBabel code

test: bin/sbu
python tests/check_run_mofid.py
python tests/check_mof_composition.py
test:
cd openbabel; \
mkdir build installed; \
cd build; \
cmake -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_INSTALL_PREFIX=../installed -DBUILD_GUI=OFF -DENABLE_TESTS=OFF -DEIGEN3_INCLUDE_DIR=../eigen -DRUN_SWIG=ON -DPYTHON_BINDINGS=ON ..; \
make -j$$(nproc) || exit 2; \
make install; \
cd $(python-packages-dir); \
test -f openbabel.pth || echo $(mofid-dir)/openbabel/installed/lib/python*/site-packages > openbabel.pth; \
cd $(mofid-dir); \
mkdir bin; \
cd bin; \
cmake -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DOpenBabel3_DIR=../openbabel/build -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON ../src/; \
make -j$$(nproc); \

unittest:
ctest --output-on-failure --test-dir bin/test

intermediatetest:
tests/check_intermediate.sh

pytest:
python tests/check_run_mofid.py; \
python tests/check_mof_composition.py

init:
cd openbabel; \
mkdir build installed; \
cd build; \
cmake -DCMAKE_INSTALL_PREFIX=../installed -DBUILD_GUI=OFF -DEIGEN3_INCLUDE_DIR=../eigen ..; \
make -j2 || exit 2; \
cmake -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_INSTALL_PREFIX=../installed -DENABLE_TESTS=OFF -DBUILD_GUI=OFF -DEIGEN3_INCLUDE_DIR=../eigen ..; \
make -j$$(nproc) || exit 2; \
make install; \
cd $(mofid-dir); \
mkdir bin; \
cd bin; \
cmake -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DOpenBabel3_DIR=../openbabel/build -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release ../src/; \
make -j$$(nproc)
# Sets up all the cmake details, so that usage is as simple as
# `bin/sbu MOF.cif` and re-compilation is as easy as `make exe`

debug:
cd openbabel; \
mkdir build installed; \
cd build; \
cmake -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_INSTALL_PREFIX=../installed -DBUILD_GUI=OFF -DENABLE_TESTS=OFF -DEIGEN3_INCLUDE_DIR=../eigen ..; \
make -j$$(nproc) || exit 2; \
make install; \
cd ../../; \
cd $(mofid-dir); \
mkdir bin; \
cd bin; \
cmake -DOpenBabel2_DIR=../openbabel/build ../src/; \
make
cmake -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DOpenBabel3_DIR=../openbabel/build ../src/ -DCMAKE_BUILD_TYPE=Debug;\
make -j$$(nproc)
# Sets up all the cmake details, so that usage is as simple as
# `bin/sbu MOF.cif` and re-compilation is as easy as `make exe`

Expand Down Expand Up @@ -91,7 +129,7 @@ init-web:
cd ../..; \
mkdir embin; \
cd embin; \
emcmake cmake -DOpenBabel2_DIR=../openbabel/embuild -static ../src/ -DCMAKE_CXX_FLAGS="-O3 --preload-file ../openbabel/data@/ob_datadir/ --preload-file ../src/Web/web_data@/web_data/ --preload-file ../Resources/RCSRnets.arc@/RCSRnets.arc --pre-js ../src/pre_emscripten.js -s TOTAL_MEMORY=128MB -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['ccall', 'cwrap', 'UTF8ToString']\""; \
emcmake cmake -DOpenBabel3_DIR=../openbabel/embuild -static ../src/ -DCMAKE_CXX_FLAGS="-O3 --preload-file ../openbabel/data@/ob_datadir/ --preload-file ../src/Web/web_data@/web_data/ --preload-file ../Resources/RCSRnets.arc@/RCSRnets.arc --pre-js ../src/pre_emscripten.js -s TOTAL_MEMORY=128MB -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['ccall', 'cwrap', 'UTF8ToString']\""; \
mkdir kekule; \
cd kekule; \
unzip ../../Resources/kekule.release.0.7.5.170624.zip; \
Expand Down
84 changes: 42 additions & 42 deletions Python/convert_smi_to_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,59 @@


def dict_to_delim(to_export, filename, delim='\t'):
with open(filename, 'w') as f:
for key in to_export:
if type(to_export[key]) is list:
for j in to_export[key]:
f.write(key + delim + str(j) + '\n')
else:
f.write(key + delim + str(to_export[key]) + '\n')
with open(filename, 'w') as f:
for key in to_export:
if type(to_export[key]) is list:
for j in to_export[key]:
f.write(key + delim + str(j) + '\n')
else:
f.write(key + delim + str(to_export[key]) + '\n')


class MOFExporter:
# Exports a .smi-formatted list of MOFid into separate tables for the various parts
def __init__(self):
self.tables = dict()
self.datatypes = list() # smiles, topology, catenation, etc.
# Exports a .smi-formatted list of MOFid into separate tables for the various parts
def __init__(self):
self.tables = dict()
self.datatypes = list() # smiles, topology, catenation, etc.

def parse(self, filename):
with open(filename, 'r') as f:
for line in f:
parsed = parse_mofid(line)
name = parsed['name']
del parsed['name']
parsed['smiles_part'] = parsed['smiles'].split('.')
parsed['base_topology'] = parsed['topology'].split(',')[0]
parsed['extra_topology'] = ','.join(parsed['topology'].split(',')[1:]) # '' if empty
self.tables[name] = copy.deepcopy(parsed)
self.datatypes = parsed.keys()
return self
def parse(self, filename):
with open(filename, 'r') as f:
for line in f:
parsed = parse_mofid(line)
name = parsed['name']
del parsed['name']
parsed['smiles_part'] = parsed['smiles'].split('.')
parsed['base_topology'] = parsed['topology'].split(',')[0]
parsed['extra_topology'] = ','.join(parsed['topology'].split(',')[1:]) # '' if empty
self.tables[name] = copy.deepcopy(parsed)
self.datatypes = parsed.keys()
return self

def _tidy_tables(self):
tidy_dict = dict()
for info in self.datatypes:
tidy_dict[info] = dict()
def _tidy_tables(self):
tidy_dict = dict()
for info in self.datatypes:
tidy_dict[info] = dict()

for mof in self.tables:
for info in self.datatypes:
tidy_dict[info][mof] = self.tables[mof][info]
for mof in self.tables:
for info in self.datatypes:
tidy_dict[info][mof] = self.tables[mof][info]

return tidy_dict
return tidy_dict

def write(self, folder='.'):
if not os.path.isdir(folder):
os.mkdir(folder)
def write(self, folder='.'):
if not os.path.isdir(folder):
os.mkdir(folder)

tidy_output = self._tidy_tables()
for key in tidy_output:
dict_to_delim(tidy_output[key], folder + '/' + key + '.tsv', delim='\t')
tidy_output = self._tidy_tables()
for key in tidy_output:
dict_to_delim(tidy_output[key], folder + '/' + key + '.tsv', delim='\t')



if __name__ == '__main__':
args = sys.argv[1:]
if len(args) != 1:
raise SyntaxError('Extract info from a list of MOFid strings. Only a single .smi filename expected.')
args = sys.argv[1:]
if len(args) != 1:
raise SyntaxError('Extract info from a list of MOFid strings. Only a single .smi filename expected.')

input_smi = args[0]
MOFExporter().parse(input_smi).write('TableOutput')
input_smi = args[0]
MOFExporter().parse(input_smi).write('TableOutput')
Loading

0 comments on commit 799c50c

Please sign in to comment.