Skip to content
Merged
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
17 changes: 17 additions & 0 deletions metatomic-core/include/metatomic/model.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
#pragma once

#include <string>

#include <metatomic.h>
#include <metatomic/errors.hpp>

namespace metatomic {
/// Render model metadata as a human-readable string.
///
/// @param metadata a JSON-serialized `ModelMetadata` object as produced by a
/// model's `metadata` callback
/// @return a human-readable rendering of the metadata
inline std::string format_metadata(const std::string& metadata) {
mta_string_t printed = nullptr;
auto status = mta_format_metadata(metadata.c_str(), &printed);
details::check_status(status);

auto result = std::string(mta_string_view(printed));
mta_string_free(printed);

return result;
}
} // namespace metatomic
20 changes: 14 additions & 6 deletions metatomic-core/tests/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ TEST_CASE("metatdata formatting") {
},
"extra": {}
})";
auto* mta_string = mta_string_create("");
REQUIRE(mta_string != nullptr);
auto status = mta_format_metadata(json.c_str(), &mta_string);
REQUIRE(status == MTA_SUCCESS);
const auto* expected = R"(This is the name model
======================

Expand All @@ -136,6 +132,18 @@ Please cite the following references when using this model:
* ref-2
* ref-3
)";
CHECK(std::string(mta_string_view(mta_string)) == expected);
mta_string_free(mta_string);

SECTION("C API") {
auto* mta_string = mta_string_create("");
REQUIRE(mta_string != nullptr);
auto status = mta_format_metadata(json.c_str(), &mta_string);
REQUIRE(status == MTA_SUCCESS);
CHECK(std::string(mta_string_view(mta_string)) == expected);
mta_string_free(mta_string);
}

SECTION("C++ API") {
auto result = metatomic::format_metadata(json);
CHECK(result == expected);
}
}
3 changes: 3 additions & 0 deletions python/metatomic_ase/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ filterwarnings = [
"ignore:`compute_requested_neighbors_from_options` is deprecated and will be removed in a future version:UserWarning",
# deprecation warning from warp/nvalchemi
"ignore:warp.config.quiet is deprecated:DeprecationWarning",
# ASE
"ignore:Setting the shape on a NumPy array:DeprecationWarning",
"ignore:Use thermalize_momenta:DeprecationWarning",
]
3 changes: 3 additions & 0 deletions python/metatomic_torch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ filterwarnings = [
"ignore:.*vesin.metatomic was only tested with metatomic.torch >=0.1.3,<0.2.*:UserWarning",
# deprecation warning from vesin
"ignore:`compute_requested_neighbors_from_options` is deprecated and will be removed in a future version:UserWarning",
# ASE
"ignore:Setting the shape on a NumPy array:DeprecationWarning",
"ignore:Use thermalize_momenta:DeprecationWarning",
]
3 changes: 3 additions & 0 deletions python/metatomic_torchsim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ filterwarnings = [
"ignore:The 'nvalchemiops.neighborlist' module has been renamed to 'nvalchemiops.neighbors':DeprecationWarning",
# deprecation warning from warp/nvalchemi
"ignore:warp.config.quiet is deprecated:DeprecationWarning",
# ASE
"ignore:Setting the shape on a NumPy array:DeprecationWarning",
"ignore:Use thermalize_momenta:DeprecationWarning",
]
Loading