-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor web-app, present settings and another test script
- Loading branch information
Showing
6 changed files
with
155 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[mpds_ml_labs] | ||
serve_ui = true | ||
ml_models = | ||
/path_to_models/model_one.pkl | ||
/path_to_models/model_two.pkl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
import os | ||
from ConfigParser import ConfigParser | ||
|
||
|
||
DATA_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), '../data')) | ||
config = ConfigParser() | ||
config_path = os.path.join(DATA_PATH, 'settings.ini') | ||
|
||
if os.path.exists(config_path): | ||
config.read(config_path) | ||
SERVE_UI = config.get('mpds_ml_labs', 'serve_ui') | ||
ML_MODELS = [path.strip() for path in filter( | ||
None, | ||
config.get('mpds_ml_labs', 'ml_models').split() | ||
)] | ||
else: | ||
SERVE_UI = True | ||
ML_MODELS = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
import os, sys | ||
|
||
from struct_utils import detect_format, poscar_to_ase, symmetrize | ||
from cif_utils import cif_to_ase | ||
from prediction import ase_to_ml_model, load_ml_model, human_names | ||
from common import ML_MODELS, DATA_PATH | ||
|
||
|
||
models, structures = [], [] | ||
|
||
if sys.argv[1:]: | ||
inputs = [f for f in sys.argv[1:] if os.path.isfile(f)] | ||
models, structures = \ | ||
[f for f in inputs if f.endswith('.pkl')], [f for f in inputs if not f.endswith('.pkl')] | ||
|
||
if not models: | ||
models = ML_MODELS | ||
|
||
if not structures: | ||
structures = [os.path.join(DATA_PATH, f) for f in os.listdir(DATA_PATH) if os.path.isfile(os.path.join(DATA_PATH, f))] | ||
|
||
active_ml_model = load_ml_model(models) | ||
|
||
for fname in structures: | ||
print(fname) | ||
structure = open(fname).read() | ||
|
||
fmt = detect_format(structure) | ||
|
||
if fmt == 'cif': | ||
ase_obj, error = cif_to_ase(structure) | ||
if error: | ||
print(error) | ||
continue | ||
|
||
elif fmt == 'poscar': | ||
ase_obj, error = poscar_to_ase(structure) | ||
if error: | ||
print(error) | ||
continue | ||
|
||
else: | ||
print('Error: %s is not a crystal structure' % fname) | ||
continue | ||
|
||
ase_obj, error = symmetrize(ase_obj) | ||
if error: | ||
print(error) | ||
continue | ||
|
||
prediction, error = ase_to_ml_model(ase_obj, active_ml_model) | ||
if error: | ||
print(error) | ||
continue | ||
|
||
for prop_id, pdata in prediction.items(): | ||
print("{0:40} = {1:6} (MAE = {2:4}), {3}".format( | ||
human_names[prop_id]['name'], | ||
pdata['value'], | ||
pdata['mae'], | ||
human_names[prop_id]['units'] | ||
)) |