diff --git a/README.md b/README.md index 0d07c5d..7b37416 100644 --- a/README.md +++ b/README.md @@ -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 -------------------- diff --git a/alignn/dataset.py b/alignn/dataset.py index 0d2e88b..36d0ba7 100644 --- a/alignn/dataset.py +++ b/alignn/dataset.py @@ -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, @@ -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.""" @@ -111,7 +113,7 @@ def atoms_to_graph(atoms): def get_torch_dataset( - dataset=[], + dataset=None, id_tag="jid", target="", target_atomwise="", @@ -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) diff --git a/alignn/ff/calculators.py b/alignn/ff/calculators.py index ebc1e6c..b2da436 100644 --- a/alignn/ff/calculators.py +++ b/alignn/ff/calculators.py @@ -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 diff --git a/alignn/ff/ff.py b/alignn/ff/ff.py index b065e4f..d935e31 100644 --- a/alignn/ff/ff.py +++ b/alignn/ff/ff.py @@ -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 @@ -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="", @@ -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, @@ -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", @@ -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, @@ -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: @@ -1381,9 +1391,9 @@ def phonons3( def ase_phonon( - atoms=[], + atoms=None, N=2, - path=[], + path=None, jid=None, calc=None, npoints=100, @@ -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 diff --git a/alignn/graphs.py b/alignn/graphs.py index a017aa2..d33d8bc 100644 --- a/alignn/graphs.py +++ b/alignn/graphs.py @@ -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 = [], [], [], [] @@ -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, ): @@ -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 @@ -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"], diff --git a/alignn/lmdb_dataset.py b/alignn/lmdb_dataset.py index 08e507c..68dcc84 100644 --- a/alignn/lmdb_dataset.py +++ b/alignn/lmdb_dataset.py @@ -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 @@ -109,7 +111,7 @@ def collate_line_graph( def get_torch_dataset( - dataset=[], + dataset=None, id_tag="jid", target="", target_atomwise="", @@ -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) diff --git a/alignn/pretrained.py b/alignn/pretrained.py index c05a9d5..8f815c7 100644 --- a/alignn/pretrained.py +++ b/alignn/pretrained.py @@ -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, @@ -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 diff --git a/alignn/scripts/cubic_mat_relax.py b/alignn/scripts/cubic_mat_relax.py index 72c540d..ebedf8f 100644 --- a/alignn/scripts/cubic_mat_relax.py +++ b/alignn/scripts/cubic_mat_relax.py @@ -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): diff --git a/alignn/scripts/make_test_split_cross_pred.py b/alignn/scripts/make_test_split_cross_pred.py index 0b7b6c4..56b8f93 100644 --- a/alignn/scripts/make_test_split_cross_pred.py +++ b/alignn/scripts/make_test_split_cross_pred.py @@ -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 = [] diff --git a/alignn/train.py b/alignn/train.py index 6af1951..0fc1f5a 100644 --- a/alignn/train.py +++ b/alignn/train.py @@ -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, @@ -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: