<commit_before>// Chemfiles, a modern library for chemistry file reading and writing
// Copyright (C) <NAME> and contributors -- BSD license

#include "catch.hpp"
#include "chemfiles.hpp"
#include "helpers.hpp"
using namespace chemfiles;

TEST_CASE("Read files in TRR format") {
    SECTION("Read trajectory: Ubiquitin") {
        auto file = Trajectory("data/trr/ubiquitin.trr");
        CHECK(file.nsteps() == 2);
        auto frame = file.read_step(0);

        CHECK(frame.step() == 0);
        CHECK(approx_eq(frame.get("time")->as_double(), 0));
        CHECK(frame.get("has_positions")->as_bool());
        CHECK(frame.size() == 20455);
        CHECK(frame.velocities());

        auto positions = frame.positions();
        CHECK(approx_eq(positions[0], Vector3D(24.8277, 24.6620, 18.8104), 1e-4));
        CHECK(approx_eq(positions[11], Vector3D(23.7713, 24.5589, 21.4702), 1e-4));

        auto velocities = *frame.velocities();
        CHECK(approx_eq(velocities[100], Vector3D(-2.8750, 2.8159, 1.2047), 1e-4));
        CHECK(approx_eq(velocities[111], Vector3D(-3.0103, 3.3177, -0.8265), 1e-4));

        auto cell = frame.cell();
        CHECK(cell.shape() == UnitCell::ORTHORHOMBIC);
        CHECK(approx_eq(cell.lengths(), {55.6800, 58.8700, 62.5700}, 1e-4));

        frame = file.read_step(1);

        CHECK(frame.step() == 25000);
        CHECK(approx_eq(frame.get("time")->as_double(), 50));
        CHECK(frame.get("has_positions")->as_bool());
        CHECK(frame.size() == 20455);
        CHECK(frame.velocities());

        positions = frame.positions();
        CHECK(approx_eq(positions[0], Vector3D(24.8625, 25.0285, 18.5973), 1e-4));
        CHECK(approx_eq(positions[11], Vector3D(23.7971, 24.2192, 21.1569), 1e-4));

        velocities = *frame.velocities();
        CHECK(approx_eq(velocities[100], Vector3D(-5.3413, -1.2646, 1.0216), 1e-4));
        CHECK(approx_eq(velocities[111], Vector3D(-1.7052, 1.0418, 5.3836), 1e-4));

        cell = frame.cell();
        CHECK(cell.shape() == UnitCell::ORTHORHOMBIC);
        CHECK(approx_eq(cell.lengths(), {55.6800, 58.8700, 62.5700}, 1e-4));
    }

    SECTION("Read trajectory: Water") {
        auto file = Trajectory("data/trr/water.trr");
        CHECK(file.nsteps() == 100);
        auto frame = file.read();

        CHECK(frame.step() == 0);
        CHECK(approx_eq(frame.get("time")->as_double(), 0));
        CHECK(frame.get("has_positions")->as_bool());
        CHECK(frame.size() == 297);
        CHECK(!frame.velocities());

        auto positions = frame.positions();
        CHECK(approx_eq(positions[0], Vector3D(0.4172, 8.3034, 11.7372), 1e-4));
        CHECK(approx_eq(positions[11], Vector3D(10.4311, 10.1225, 4.1827), 1e-4));

        auto cell = frame.cell();
        CHECK(cell.shape() == UnitCell::ORTHORHOMBIC);
        CHECK(approx_eq(cell.lengths(), {15.0, 15.0, 15.0}, 1e-4));

        file.read(); // Skip a frame
        frame = file.read();

        CHECK(frame.step() == 2);
        CHECK(approx_eq(frame.get("time")->as_double(), 0.2, 1e-4));
        CHECK(frame.get("has_positions")->as_bool());
        CHECK(frame.size() == 297);<commit_msg>feat(tests): read double precision TRR<commit_after>// Chemfiles, a modern library for chemistry file reading and writing
// Copyright (C) <NAME> and contributors -- BSD license

#include "catch.hpp"
#include "chemfiles.hpp"
#include "helpers.hpp"
using namespace chemfiles;

static void check_ubiquitin(Trajectory& file) {
    CHECK(file.nsteps() == 2);
    auto frame = file.read_step(0);

    CHECK(frame.step() == 0);
    CHECK(approx_eq(frame.get("time")->as_double(), 0));
    CHECK(frame.get("has_positions")->as_bool());
    CHECK(frame.size() == 20455);
    CHECK(frame.velocities());

    auto positions = frame.positions();
    CHECK(approx_eq(positions[0], Vector3D(24.8277, 24.6620, 18.8104), 1e-4));
    CHECK(approx_eq(positions[11], Vector3D(23.7713, 24.5589, 21.4702), 1e-4));

    auto velocities = *frame.velocities();
    CHECK(approx_eq(velocities[100], Vector3D(-2.8750, 2.8159, 1.2047), 1e-4));
    CHECK(approx_eq(velocities[111], Vector3D(-3.0103, 3.3177, -0.8265), 1e-4));

    auto cell = frame.cell();
    CHECK(cell.shape() == UnitCell::ORTHORHOMBIC);
    CHECK(approx_eq(cell.lengths(), {55.6800, 58.8700, 62.5700}, 1e-4));

    frame = file.read_step(1);

    CHECK(frame.step() == 25000);
    CHECK(approx_eq(frame.get("time")->as_double(), 50));
    CHECK(frame.get("has_positions")->as_bool());
    CHECK(frame.size() == 20455);
    CHECK(frame.velocities());

    positions = frame.positions();
    CHECK(approx_eq(positions[0], Vector3D(24.8625, 25.0285, 18.5973), 1e-4));
    CHECK(approx_eq(positions[11], Vector3D(23.7971, 24.2192, 21.1569), 1e-4));

    velocities = *frame.velocities();
    CHECK(approx_eq(velocities[100], Vector3D(-5.3413, -1.2646, 1.0216), 1e-4));
    CHECK(approx_eq(velocities[111], Vector3D(-1.7052, 1.0418, 5.3836), 1e-4));

    cell = frame.cell();
    CHECK(cell.shape() == UnitCell::ORTHORHOMBIC);
    CHECK(approx_eq(cell.lengths(), {55.6800, 58.8700, 62.5700}, 1e-4));
}

TEST_CASE("Read files in TRR format") {
    SECTION("Read trajectory: Ubiquitin") {
        auto file = Trajectory("data/trr/ubiquitin.trr");
        check_ubiquitin(file);
    }

    SECTION("Read double precision trajectory: Ubiquitin") {
        auto file = Trajectory("data/trr/ubiquitin_d.trr");
        check_ubiquitin(file);
    }

    SECTION("Read trajectory: Water") {
        auto file = Trajectory("data/trr/water.trr");
        CHECK(file.nsteps() == 100);
        auto frame = file.read();

        CHECK(frame.step() == 0);
        CHECK(approx_eq(frame.get("time")->as_double(), 0));
        CHECK(frame.get("has_positions")->as_bool());
        CHECK(frame.size() == 297);
        CHECK(!frame.velocities());

        auto positions = frame.positions();
        CHECK(approx_eq(positions[0], Vector3D(0.4172, 8.3034, 11.7372), 1e-4));
        CHECK(approx_eq(positions[11], Vector3D(10.4311, 10.1225, 4.1827), 1e-4));

        auto cell = frame.cell();
        CHECK(cell.shape() == UnitCell::ORTHORHOMBIC);
        CHECK(approx_eq(cell.lengths(), {15.0, 15.0, 15.0}, 1e-4));

        file.read(); // Skip a frame
        frame = file.read();

        CHECK(frame.step() == 2);
        CHECK(approx_eq(frame.get("time")->as_double(), 0.2, 1e-4));
        CHECK(frame.get("has_positions")->as_bool());
        CHECK(frame.size() == 297);
{'fraction_non_alphanumeric': 0.19106699751861042, 'fraction_numerical': 0.0946029776674938, 'mean_word_length': 3.2567656765676567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5769572', 'n_tokens_mistral': 2727, 'n_tokens_neox': 2310, 'n_words': 389}