Skip to content

Commit

Permalink
updates - restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkhorana committed Mar 25, 2024
1 parent e88f5f0 commit 373940b
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 42 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name:CI

on:
push:
pull_request:

jobs:
run-tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version:
- "3.11"

name: Test
runs-on: ${{matrix.os}}

steps:
- name: checkout
uses: actions/checkout@v3

- name: setup
uses: actions/setup-python@v4
with:
python-version: ${{matrix.python-version}}

- name: install deps
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: run tests
run: pytest
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[build-system]
requires = ["setuptools>=42.0", "wheel"]
build-backend = "setuptools.build_meta"

[tools.pytest.ini_options]
adopts = '--cov=complexes'
testpaths = [
"tests"
]

[mypy]
mypy_path = "src"
check_untyped_defs = false
disallow_any_generics = false
ignore_missing_imports = true
show_error_codes = true
ignore_errors = true
17 changes: 16 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,33 @@ beautifulsoup4==4.12.3
biopandas==0.5.1.dev0
biopython==1.83
bioservices==1.11.2
black==24.3.0
bleach==6.1.0
botorch==0.10.0
cachetools==5.3.3
cattrs==23.2.3
certifi==2024.2.2
cffi==1.16.0
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
colorlog==6.8.2
comm==0.2.2
contourpy==1.2.0
coverage==7.4.4
cycler==0.12.1
debugpy==1.8.1
decorator==5.1.1
deepdiff==6.7.1
defusedxml==0.7.1
dill==0.3.8
distlib==0.3.8
easydev==0.13.1
executing==2.0.1
fastjsonschema==2.19.1
filelock==3.13.1
flake8==7.0.0
fonttools==4.50.0
fqdn==1.5.1
fsspec==2024.3.1
Expand All @@ -42,13 +48,13 @@ gevent==24.2.1
gmsh==4.12.2
gmsh_interop==2021.1.1
gpytorch==1.11
graphein==1.7.6
greenlet==3.0.3
grequests==0.7.0
h11==0.14.0
httpcore==1.0.4
httpx==0.27.0
idna==3.6
iniconfig==2.0.0
ipykernel==6.29.3
ipython==8.22.2
isoduration==20.11.0
Expand Down Expand Up @@ -82,6 +88,7 @@ markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.8.3
matplotlib-inline==0.1.6
mccabe==0.7.0
mdurl==0.1.2
meshio==5.3.5
MeshPy==2022.1.3
Expand All @@ -92,6 +99,7 @@ mmtf-python==1.1.3
mpmath==1.3.0
msgpack==1.0.8
multipledispatch==1.0.0
mypy==1.9.0
mypy-extensions==1.0.0
nbclient==0.10.0
nbconvert==7.16.3
Expand All @@ -112,20 +120,26 @@ pexpect==4.9.0
pillow==10.2.0
platformdirs==4.2.0
plotly==5.20.0
pluggy==1.4.0
prometheus_client==0.20.0
prompt-toolkit==3.0.43
psutil==5.9.8
ptyprocess==0.7.0
pure-eval==0.2.2
pybind11==2.11.1
pycodestyle==2.11.1
pycparser==2.21
pydantic==1.10.14
pyflakes==3.2.0
Pygments==2.17.2
pygmsh==7.1.17
pyparsing==3.1.2
pyproject-api==1.6.1
pyquaternion==0.9.9
pyro-api==0.1.2
pyro-ppl==1.9.0
pytest==8.1.1
pytest-cov==5.0.0
python-dateutil==2.9.0.post0
python-json-logger==2.0.7
pytools==2024.1.1
Expand Down Expand Up @@ -168,6 +182,7 @@ tzdata==2024.1
uri-template==1.3.0
url-normalize==1.4.3
urllib3==2.2.1
virtualenv==20.25.1
wcwidth==0.2.13
webcolors==1.13
webencodings==0.5.1
Expand Down
25 changes: 25 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[metadata]
name = complexes
description = atomistic system modeling
author = Rahul Khorana
license = MIT
license_file = LICENSE
platforms = unix, linux, osx
classifiers =
Programming Language :: Python :: 3.11

[options]
packages =
complexes
install_requires =
requests >= 2
python_requires = >= 3.11
package_dir = src
zip_safe = no

[flake8]
max-line-length = 160

[mypy]
ignore_missing_imports = True
ignore_errors = True
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from setuptools import setup

if __name__ == "__main__":
setup()
File renamed without changes.
23 changes: 13 additions & 10 deletions src/atomic_complex.py → src/complexes/atomic_complex.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import jax
import numpy as np
from typing import List, Tuple
from building_blocks import Electron, Proton, Neutron
from general_utils import GeneralComplexUtils
from complexes.building_blocks import Electron, Proton, Neutron
from complexes.general_utils import GeneralComplexUtils


seed = np.random.randint(0, 10 * 3)
Expand Down Expand Up @@ -143,7 +143,7 @@ def general_build_complex(
self.build_electrons()
assert isinstance(using_distances, bool)
K = np.asarray([])
while self.AP:
while self.AP and self.P > 0:
p = self.AP.pop()
p = np.asarray(p, dtype=np.float32)
res = gcu.get_nsphere_and_sampled_boundary(
Expand All @@ -154,7 +154,7 @@ def general_build_complex(
gluing_map = gcu.nuclear_force_map(boundary, boundary, K)
K = gcu.topological_disjoint_union(gluing_map, K, n_sphere)

while self.AN:
while self.AN and self.N > 0:
n = self.AN.pop()
n = np.asarray(n, dtype=np.float32)
res = gcu.get_nsphere_and_sampled_boundary(
Expand All @@ -165,11 +165,14 @@ def general_build_complex(
gluing_map = gcu.nuclear_force_map(boundary, boundary, K)
K = gcu.topological_disjoint_union(gluing_map, K, n_sphere)

while self.AE:
while self.AE and self.E > 0:
e, we = self.AE.pop()
if using_distances and hasattr(update_distances, "__call__"):
update_distances(self.DE, we, e)
ec = np.array([e[0] for _ in range(len(n[0]))])
try:
ec = np.array([e[0] for _ in range(len(n[0]))])
except Exception:
ec = np.array([e[0] for _ in range(self.P + self.E)])
res = gcu.get_nsphere_and_sampled_boundary(
radius=2.8 * fm, center=ec, sample=10000, eps=1e-19
)
Expand All @@ -190,14 +193,14 @@ def sanity_test(kind, *args):
if kind == "general":
try:
ac.general_build_complex()
print(f"success ✅")
except:
print("success ✅")
except Exception:
print("failed ❌")
else:
try:
ac.fast_build_complex()
print(f"success ✅")
except:
print("success ✅")
except Exception:
print("failed ❌")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dill
import numpy as np
from collections import defaultdict
from atomic_complex import AtomComplex
from complexes.atomic_complex import AtomComplex


class BuildAtoms:
Expand Down Expand Up @@ -46,7 +46,7 @@ def sanity(self):
assert isinstance(table["Bk"], tuple)
assert isinstance(table["Bk"][0], np.ndarray)
print("Success ✅")
except:
except Exception:
print("Failed ❌")


Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/core_utils.py → src/complexes/core_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import re
import jax
import numpy as np
import jax.numpy as jnp
from typing import Tuple
from collections import defaultdict

Expand Down
8 changes: 4 additions & 4 deletions src/general_utils.py → src/complexes/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, Tuple
from collections import defaultdict
from microstructpy.geometry.n_sphere import NSphere
from core_utils import GluingMap
from complexes.core_utils import GluingMap


class GeneralComplexUtils:
Expand Down Expand Up @@ -48,7 +48,7 @@ def centered_2_norm(self, X: np.array, center: np.array) -> np.float32:

def get_nsphere_and_sampled_boundary(
self, radius: np.float32, center: np.ndarray, sample: int, eps: np.float32
) -> List[list, np.ndarray]:
) -> Tuple[list, np.ndarray]:
representation = NSphere(r=radius, center=center)
nsphere = representation.approximate()
dim = center.shape[0]
Expand Down Expand Up @@ -80,8 +80,8 @@ def compute_norm(mat: np.ndarray) -> jnp.float32:
remain = dim - len(boundary)
if remain == dim:
limits = representation.limits
for l in limits[0]:
boundary.append(l)
for lim in limits[0]:
boundary.append(lim)
rem = dim - len(boundary)
for _ in range(rem):
eps = np.random.randint(0, 10 * 2) * 1e-19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np
import jax.numpy as jnp
from typing import List, Tuple
from core_utils import GluingMap, ElectronField
from building_blocks import Electron
from complexes.core_utils import GluingMap, ElectronField
from complexes.building_blocks import Electron


class PolyAtomComplex:
Expand Down Expand Up @@ -102,8 +102,8 @@ def dir_sum(a: np.ndarray, b: np.ndarray) -> np.ndarray:
return dsum

while A:
I = A.pop(0)
num_elec, k, _, df, de = I
data = A.pop(0)
num_elec, k, _, df, de = data
if len(C) == 0:
C = k
phi = GluingMap(C, k, target=C).construct_map()
Expand All @@ -127,14 +127,14 @@ def sanity_test(atom_list, kind):
if kind == "general":
try:
pac.general_build_complex()
print(f"success ✅")
except:
print("success ✅")
except Exception:
print("failed ❌")
else:
try:
pac.fast_build_complex()
print(f"success ✅")
except:
print("success ✅")
except Exception:
print("failed ❌")


Expand Down
6 changes: 3 additions & 3 deletions src/process_esol.py → src/complexes/process_esol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
from rdkit import Chem
from collections import defaultdict
from polyatomic_complex import PolyAtomComplex
from complexes.polyatomic_complex import PolyAtomComplex


class ProcessESOL:
Expand Down Expand Up @@ -65,8 +65,8 @@ def smiles_to_atoms(self, smile: str) -> list:
for k in atom_counts:
cleaned = regex.sub(" ", k).split(" ")
res = []
for l in cleaned:
r = l.strip()
for ch in cleaned:
r = ch.strip()
if r != "" and " " not in r:
res.append(r)
atoms_list += res
Expand Down
6 changes: 3 additions & 3 deletions src/process_freesolv.py → src/complexes/process_freesolv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
from rdkit import Chem
from collections import defaultdict
from polyatomic_complex import PolyAtomComplex
from complexes.polyatomic_complex import PolyAtomComplex


class ProcessFreeSolv:
Expand Down Expand Up @@ -65,8 +65,8 @@ def smiles_to_atoms(self, smile: str) -> list:
for k in atom_counts:
cleaned = regex.sub(" ", k).split(" ")
res = []
for l in cleaned:
r = l.strip()
for ch in cleaned:
r = ch.strip()
if r != "" and " " not in r:
res.append(r)
atoms_list += res
Expand Down
Loading

0 comments on commit 373940b

Please sign in to comment.