Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ NIST-MGI (https://www.nist.gov/mgi)

NIST-CHIPS (https://www.nist.gov/chips)

Note: This project was originally developed under the github.com/usnistgov organization. New updates and developments will be carried out here.

Code of conduct
--------------------

Expand Down
8 changes: 6 additions & 2 deletions alignn/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# NOTE: Use lmd_dataset,
# need to fix adding lattice in dataloader
def load_graphs(
dataset=[],
dataset=None,
name: str = "dft_3d",
neighbor_strategy: str = "k-nearest",
cutoff: float = 8,
Expand All @@ -42,6 +42,8 @@ def load_graphs(
edata_schemes={'r': Scheme(shape=(3,)})
```
"""
if dataset is None:
dataset = []

def atoms_to_graph(atoms):
"""Convert structure dict to DGLGraph."""
Expand Down Expand Up @@ -111,7 +113,7 @@ def atoms_to_graph(atoms):


def get_torch_dataset(
dataset=[],
dataset=None,
id_tag="jid",
target="",
target_atomwise="",
Expand All @@ -132,6 +134,8 @@ def get_torch_dataset(
dtype="float32",
):
"""Get Torch Dataset."""
if dataset is None:
dataset = []
df = pd.DataFrame(dataset)
# df['natoms']=df['atoms'].apply(lambda x: len(x['elements']))
# print(" data df", df)
Expand Down
50 changes: 26 additions & 24 deletions alignn/ff/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,32 +398,34 @@ def __init__(
ff_config_filename="config.json",
ff_config=None,
stress_wt=0.05,
props=[
"cbm",
"vbm",
"gap",
"efermi",
"optb88vdw_bandgap",
"mbj_bandgap",
"spillage",
"slme",
"bulk_modulus_kv",
"shear_modulus_gv",
"n-Seebeck",
"n-powerfact",
"avg_elec_mass",
"avg_hole_mass",
"epsx",
"mepsx",
"max_efg",
"dfpt_piezo_max_dielectric",
"dfpt_piezo_max_dij",
"exfoliation_energy",
"Tc_supercon",
"magmom_oszicar",
],
props=None























):
"""Initialize class."""
if props is None:
props = []
super().__init__()
# super().__init__(**kwargs)
self.device = device
Expand Down
28 changes: 21 additions & 7 deletions alignn/ff/ff.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,13 +949,15 @@ def surface_energy(
on_conventional_cell=True,
dataset="dft_3d",
max_index=None,
miller_index=[1, 1, 1],
miller_index=None,
on_relaxed_struct=True,
model_path=".",
thickness=25,
model_filename="best_model.pt",
):
"""Get surface energy."""
if miller_index is None:
miller_index = []
if atoms is None:
from jarvis.db.figshare import data

Expand Down Expand Up @@ -1030,8 +1032,8 @@ def surface_energy(
def get_interface_energy(
film_atoms=None,
subs_atoms=None,
film_index=[1, 1, 1],
subs_index=[0, 0, 1],
film_index=None,
subs_index=None,
film_thickness=25,
subs_thickness=25,
model_path="",
Expand All @@ -1046,6 +1048,10 @@ def get_interface_energy(
gpaw_verify=False,
):
"""Get work of adhesion."""
if film_index is None:
film_index = []
if subs_index is None:
subs_index = []
film_surf = Surface(
film_atoms,
indices=film_index,
Expand Down Expand Up @@ -1173,7 +1179,7 @@ def phonons(
force_mult_natoms=False,
stress_wt=0.1,
force_multiplier=1,
dim=[2, 2, 2],
dim=None,
freq_conversion_factor=33.3566830, # ThztoCm-1
phonopy_bands_figname="phonopy_bands.png",
# phonopy_dos_figname="phonopy_dos.png",
Expand All @@ -1182,6 +1188,8 @@ def phonons(
distance=0.2,
):
"""Make Phonon calculation setup."""
if dim is None:
dim = []
if calc is None:
calc = AlignnAtomwiseCalculator(
path=model_path,
Expand Down Expand Up @@ -1322,12 +1330,14 @@ def phonons3(
model_path=".",
model_filename="best_model.pt",
on_relaxed_struct=False,
dim=[2, 2, 2],
dim=None,
distance=0.2,
stress_wt=0.1,
force_multiplier=1,
):
"""Make Phonon3 calculation setup."""
if dim is None:
dim = []
from phono3py import Phono3py

if calc is None:
Expand Down Expand Up @@ -1381,9 +1391,9 @@ def phonons3(


def ase_phonon(
atoms=[],
atoms=None,
N=2,
path=[],
path=None,
jid=None,
calc=None,
npoints=100,
Expand All @@ -1397,6 +1407,10 @@ def ase_phonon(
force_multiplier=1,
):
"""Get phonon bandstructure and DOS using ASE."""
if atoms is None:
atoms = []
if path is None:
path = []
if calc is None:
calc = AlignnAtomwiseCalculator(
path=model_path, force_multiplier=force_multiplier
Expand Down
24 changes: 18 additions & 6 deletions alignn/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ def nearest_neighbor_edges(

def build_undirected_edgedata(
atoms=None,
edges={},
edges=None,
):
"""Build undirected graph data from edge set.

edges: dictionary mapping (src_id, dst_id) to set of dst_image
r: cartesian displacement vector from src -> dst
"""
if edges is None:
edges = {}
# second pass: construct *undirected* graph
# import pprint
u, v, r, all_images = [], [], [], []
Expand Down Expand Up @@ -440,10 +442,10 @@ class Graph(object):

def __init__(
self,
nodes=[],
node_attributes=[],
edges=[],
edge_attributes=[],
nodes=None,
node_attributes=None,
edges=None,
edge_attributes=None,
color_map=None,
labels=None,
):
Expand All @@ -461,6 +463,14 @@ def __init__(
edge_attributes: attributes for each connectivity.
as simple as euclidean distances.
"""
if nodes is None:
nodes = []
if node_attributes is None:
node_attributes = []
if edges is None:
edges = []
if edge_attributes is None:
edge_attributes = []
self.nodes = nodes
self.node_attributes = node_attributes
self.edges = edges
Expand Down Expand Up @@ -753,8 +763,10 @@ def num_edges(self):
return len(self.edges)

@classmethod
def from_dict(self, d={}):
def from_dict(self, d=None):
"""Constuct class from a dictionary."""
if d is None:
d = {}
return Graph(
nodes=d["nodes"],
edges=d["edges"],
Expand Down
8 changes: 6 additions & 2 deletions alignn/lmdb_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def prepare_line_graph_batch(
class TorchLMDBDataset(Dataset):
"""Dataset of crystal DGLGraphs using LMDB."""

def __init__(self, lmdb_path="", line_graph=True, ids=[]):
def __init__(self, lmdb_path="", line_graph=True, ids=None):
"""Intitialize with path and ids array."""
if ids is None:
ids = []
super(TorchLMDBDataset, self).__init__()
self.lmdb_path = lmdb_path
self.ids = ids
Expand Down Expand Up @@ -109,7 +111,7 @@ def collate_line_graph(


def get_torch_dataset(
dataset=[],
dataset=None,
id_tag="jid",
target="",
target_atomwise="",
Expand All @@ -133,6 +135,8 @@ def get_torch_dataset(
dtype="float32",
):
"""Get Torch Dataset with LMDB."""
if dataset is None:
dataset = []
vals = np.array([ii[target] for ii in dataset]) # df[target].values
print("data range", np.max(vals), np.min(vals))
print("line_graph", line_graph)
Expand Down
8 changes: 6 additions & 2 deletions alignn/pretrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ def get_prediction(


def get_multiple_predictions(
atoms_array=[],
jids=[],
atoms_array=None,
jids=None,
cutoff=8,
neighbor_strategy="k-nearest",
max_neighbors=12,
Expand All @@ -390,6 +390,10 @@ def get_multiple_predictions(
# use_lmdb=True,
):
"""Use pretrained model on a number of structures."""
if atoms_array is None:
atoms_array = []
if jids is None:
jids = []
# if use_lmdb:
# print("Using LMDB dataset.")
# from alignn.lmdb_dataset import get_torch_dataset
Expand Down
4 changes: 3 additions & 1 deletion alignn/scripts/cubic_mat_relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
# model_path = "/wrk/knc6/ALINN_FC/ALIGNNFF_DB/temp_new"


def relax(model_path=[]):
def relax(model_path=None):
if model_path is None:
model_path = []
exp_a = []
aff_a = []
for i in tqdm(d):
Expand Down
4 changes: 3 additions & 1 deletion alignn/scripts/make_test_split_cross_pred.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@


def predict_for_db(
name="dft_3d", prop="formation_energy_peratom", id_tag="jid", ids=[]
name="dft_3d", prop="formation_energy_peratom", id_tag="jid", ids=None
):
"""Predict using ALIGNN for a DB."""
if ids is None:
ids = []
db = data(name)
df = pd.DataFrame(db)
x = []
Expand Down
4 changes: 3 additions & 1 deletion alignn/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def train_dgl(
config: Union[TrainingConfig, Dict[str, Any]],
model: nn.Module = None,
# checkpoint_dir: Path = Path("./"),
train_val_test_loaders=[],
train_val_test_loaders=None,
rank=0,
world_size=0,
# log_tensorboard: bool = False,
Expand All @@ -60,6 +60,8 @@ def train_dgl(
`config` should conform to alignn.conf.TrainingConfig, and
if passed as a dict with matching keys, pydantic validation is used
"""
if train_val_test_loaders is None:
train_val_test_loaders = []
# print("rank", rank)
# setup(rank, world_size)
if rank == 0:
Expand Down
Loading