Skip to content

Commit

Permalink
update mcloud implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Nov 9, 2023
1 parent d7fd87a commit cec0604
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

.vscode
120 changes: 120 additions & 0 deletions src/mcloud_implementation/landing_page/index.html.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Materials Cloud OPTIMADE server</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="shortcut icon" href="/static/images/favicon.png" type="image/png" />

<link rel="stylesheet" href="/static/css/mcloud_theme.min.css" type='text/css'>
<link rel="stylesheet" href="/static/css/extra.css" type='text/css'>

<script src="/static/js/jquery.min.js" type='text/javascript'></script>
<script src="/static/js/bootstrap.min.js" type='text/javascript'></script>

</head>

<body>

<!-- Add script Plausible and pass domain name ad rollup name as parameter -->
<script type="text/javascript">
var header = document.getElementsByTagName("head")[0];
var plausible = document.createElement("script");
var domain_name = window.location.hostname;
var rollup_name = "plausible-rollup.materialscloud.org";

plausible.async = "";
plausible.defer = "";
plausible.dataset["domain"] = domain_name + "," + rollup_name;
plausible.src = "https://plausible.io/js/plausible.js";
header.appendChild(plausible);
</script>
<!-- end Plausible analytics -->

<div class="extra-container">
<!-- Application header -->
<div class="mcloud-header header" id="mcloudHeader">
<div class="navbar navbar-default navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button class="navbar-toggle" data-target=".header-collapse" data-toggle="collapse"
type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://www.materialscloud.org/home">
<img src="static/images/mcloud_logo.png">
</a>
</div>

<div class="collapse navbar-collapse header-collapse">
<ul class="nav navbar-nav">
<li><a href="https://www.materialscloud.org/learn">LEARN</a></li>
<li><a href="https://www.materialscloud.org/work">WORK</a></li>
<li><a href="https://www.materialscloud.org/discover">DISCOVER</a></li>
<li><a href="https://www.materialscloud.org/explore">EXPLORE</a></li>
<li><a href="https://www.materialscloud.org/archive">ARCHIVE</a></li>
</ul>
</div>
</div>
</div>
</div> <!-- End of header -->


<div class="mcloud-wrapper extra-expand-bottom">

<div class="mcloud-status-bar">
</div>
<div class="mcloud-message-container">
</div>
<!-- Application body -->
<div class="mcloud-container">
<div class="mcloud-page-container">
<div class="extra-page-content">
<div class="extra-title-logos">
<h3>Materials Cloud Archive OPTIMADE server</h3>
<div style="padding: 1em;">
<span style="padding: 1em">
<img height="60px"
src="https://matsci.org/uploads/default/original/2X/b/bd2f59b3bf14fb046b74538750699d7da4c19ac1.svg">
</span>
<span style="padding: 1em">
<img height="60px"
src="https://raw.githubusercontent.com/materialscloud-org/discover-mc3d-react/main/public/mcloud_spinner.svg">
</span>
</div>
</div>
<h4>Index meta-database:</h4>
<ul>
<li><a href='/index/v1/info'>/index/v1/info</a></li>
<li><a href='/index/v1/links'>/index/v1/links</a></li>
</ul>
<h4>Available databases:</h4>

<table>
<thead>
<tr>
<th>Date</th>
<th>Archive entry</th>
<th>OPTIMADE endpoint</th>
</tr>
</thead>
<tbody>
$HTML_TABLE_ROWS
</tbody>
</table>

</div>
</div>
</div>

</div>

</div>
</body>

</html>
54 changes: 54 additions & 0 deletions src/mcloud_implementation/landing_page/static/css/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.extra-container {
display: flex;
flex-direction: column;
min-height: 100vh;
}

.extra-expand-bottom {
flex: 1;
}

.extra-page-content {
margin: auto;
max-width: 900px;
background-color: white;
min-height: 650px;
padding: 20px 40px;
margin-bottom: 30px;
}

.extra-title-logos {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-bottom: 6px;
}


table {
/* font-family: Arial, sans-serif; */
border-collapse: collapse;
width: 90%;
margin: 0 auto;
font-size: 14px;
}

th,
td {
border: 1px solid #EEEEEE;
text-align: left;
padding: 8px;
}

th {
background-color: #f0f0f0;
}

/* tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:nth-child(odd) {
background-color: #ffffff;
} */

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions src/mcloud_implementation/mcloud_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,14 @@ def _start_containers():
output = subprocess.check_output(command, shell=True).decode("utf-8")
print(output)
print(f"-- finished! Time: {time() - start_time:.2f}")
except subprocess.CalledProcessError:
print(
f"INFO: {db} profile create excepted,"
"but continuing with server start..."
)
print(traceback.format_exc())

try:
print("---- optimade-launch server start")
start_time = time()
command = f"optimade-launch -vvv server start -p {doi_id}"
Expand Down Expand Up @@ -427,7 +434,7 @@ def _update_landing_page():

from string import Template

p = Path(__file__).with_name("landing_page.html.template")
p = Path(__file__).parent / "landing_page" / "index.html.template"
with p.open("r") as f:
landing_page_template = Template(f.read())

Expand All @@ -444,29 +451,24 @@ def _update_landing_page():
db_list_html = ""
for row in rows:
date, doi_id, metadata = row
base_url = urljoin(BASE_URL, f"archive/{doi_id}")
metadata_html = ""
date_val = "-"
title_val = "-"
if date:
metadata_html = f"<a href='{metadata.get('url')}'>"
metadata_html += date.strftime("%Y.%m.%d") + " "
metadata_html += (
f"{metadata.get('title')} (version v{metadata.get('version')})"
)
metadata_html += "</a>; "

date_val = date.strftime("%Y.%m.%d")
title_val = f"<a href='{metadata.get('url')}'>"
title_val += metadata.get("title")
ver = metadata.get("version")
if ver > 1:
title_val += f" (version v{ver})"
title_val += "</a>"
endpoint = f"<a href='/archive/{doi_id}'>/archive/{doi_id}</a>"
db_list_html += (
f"<li>{metadata_html}OPTIMADE endpoint:"
+ f"<a href='{base_url}'>{base_url}</a></li>\n"
f"<tr><td>{date_val}</td><td>{title_val}</td><td>{endpoint}</td></tr>"
)

index_html_loc = "/var/www/html/index.html"
with open(index_html_loc, "w") as f:
f.write(
landing_page_template.substitute(
HTML_DB_LIST_ENTRIES=db_list_html,
INDEX_BASE_URL=BASE_URL_INDEX,
)
)
f.write(landing_page_template.substitute(HTML_TABLE_ROWS=db_list_html))


@click.command()
Expand Down
22 changes: 22 additions & 0 deletions src/mcloud_implementation/version_redirect.html.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<!DOCTYPE html>
<html lang="en">
<head>
<title>Materials Cloud OPTIMADE server</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="optimade,materials,crystals,database">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<style>
html { margin: 2em; }
h4, p { margin-left: 2em; }
span.version { background-color: lightgrey; font-weight: bold; font-family: monospace; padding: 0em 0.5em 0em 0.5em; border-radius: 1em; }
</style>
</head>
<body>
This archive entry has a new version available and the current one is not served any more.
<br/>
OPTIMADE API for the new version is available at $NEW_URL
</body>
</html>

0 comments on commit cec0604

Please sign in to comment.