Compare commits
19 Commits
add_ai_rev
...
mschoi-pat
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ab41e7c0b | |||
| fff417b041 | |||
| 5c6a86815d | |||
| 0e64fe9cf5 | |||
| bbd57d0344 | |||
| 849fc5de11 | |||
| b679ccfbe6 | |||
| 393a909eb2 | |||
| 33cdd99dde | |||
| a433d213f2 | |||
| 36f0e16bce | |||
| 516c36c564 | |||
| b28e6a033e | |||
| b97a34a642 | |||
| 6e94041482 | |||
| 9373d31dbc | |||
| 5d998bd24b | |||
| b88213f200 | |||
| f1f43abea8 |
@@ -213,6 +213,8 @@ def analyze_full_context(
|
||||
file_contents.append(f"File: {file}")
|
||||
file_contents.append(content)
|
||||
file_contents.append(f"Diff: {chunk}")
|
||||
if not file_contents:
|
||||
return ""
|
||||
|
||||
title = EVENT_DATA["pull_request"]["title"]
|
||||
description = EVENT_DATA["pull_request"]["body"]
|
||||
|
||||
@@ -26,8 +26,8 @@ jobs:
|
||||
- name: Run Code Review
|
||||
env:
|
||||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
FULL_CONTEXT_MODEL: gpt-4o
|
||||
FULL_CONTEXT_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
FULL_CONTEXT_MODEL: deepseek-reasoner
|
||||
FULL_CONTEXT_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
|
||||
SINGLE_CHUNK_MODEL: gpt-4o
|
||||
SINGLE_CHUNK_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
EXCLUDE: "*.yml,*.yaml"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
|
||||
@@ -6,3 +6,5 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
nalgebra = "0.33.2"
|
||||
approx = "0.5"
|
||||
20
src/context.rs
Normal file
20
src/context.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use crate::integrator::Integrator;
|
||||
use crate::platform::Platform;
|
||||
use crate::state::{State, StateType};
|
||||
use crate::system::System;
|
||||
use nalgebra::Vector3;
|
||||
|
||||
pub struct Context {
|
||||
pub system: System,
|
||||
pub integrator: Box<dyn Integrator>,
|
||||
pub platform: Box<dyn Platform>,
|
||||
}
|
||||
impl Context {
|
||||
pub fn set_positions(&mut self, _positions: Vec<Vector3<f32>>) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_state(&self, _state_type: StateType) -> State {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
179
src/force/harmonic_angle_force.rs
Normal file
179
src/force/harmonic_angle_force.rs
Normal file
@@ -0,0 +1,179 @@
|
||||
use crate::context::Context;
|
||||
use crate::force::Force;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct HarmonicAngleForce {}
|
||||
impl HarmonicAngleForce {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn add_angle(
|
||||
&mut self,
|
||||
_particle1: usize,
|
||||
_particle2: usize,
|
||||
_particle3: usize,
|
||||
_angle: f64,
|
||||
_k: f64,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_angle_parameters(
|
||||
&mut self,
|
||||
_angle_id: usize,
|
||||
_particle1: usize,
|
||||
_particle2: usize,
|
||||
_particle3: usize,
|
||||
_angle: f64,
|
||||
_k: f64,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Force for HarmonicAngleForce {
|
||||
fn update_parameters_in_context(&mut self, _context: &mut Context) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn set_periodic_boundary_conditions(&mut self, _status: bool) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn use_periodic_boundary_conditions(&self) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for HarmonicAngleForce {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::HarmonicAngleForce;
|
||||
use crate::context::Context;
|
||||
use crate::force::Force;
|
||||
use crate::integrator::VerletIntegrator;
|
||||
use crate::platform::CPU;
|
||||
use crate::state::StateType;
|
||||
use crate::system::System;
|
||||
use approx::assert_relative_eq;
|
||||
use nalgebra::Vector3;
|
||||
use std::f64::consts::PI;
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_harmonic_angle_force() {
|
||||
let mut system = System::new();
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
let integrator = VerletIntegrator { dt: 0.01 };
|
||||
|
||||
let mut forcefield = HarmonicAngleForce::new();
|
||||
forcefield.add_angle(0, 1, 2, PI / 3.0, 1.1);
|
||||
forcefield.add_angle(1, 2, 3, PI / 2.0, 1.2);
|
||||
|
||||
system.add_force(Box::new(forcefield.clone()));
|
||||
assert_eq!(forcefield.use_periodic_boundary_conditions(), false);
|
||||
assert_eq!(system.use_periodic_boundary_conditions(), false);
|
||||
|
||||
let mut context = Context {
|
||||
system,
|
||||
integrator: Box::new(integrator),
|
||||
platform: Box::new(CPU),
|
||||
};
|
||||
|
||||
let mut positions = vec![Vector3::zeros(); 4];
|
||||
positions[0] = Vector3::new(0.0, 2.0, 0.0);
|
||||
positions[1] = Vector3::new(0.0, 0.0, 0.0);
|
||||
positions[2] = Vector3::new(1.0, 0.0, 0.0);
|
||||
positions[3] = Vector3::new(2.0, 1.0, 0.0);
|
||||
|
||||
context.set_positions(positions);
|
||||
let state = context.get_state(StateType::Either);
|
||||
let forces = state.get_forces();
|
||||
let torque1 = 1.1 * PI / 6.0;
|
||||
let torque2 = 1.2 * PI / 4.0;
|
||||
assert_relative_eq!(forces[0], Vector3::new(torque1, 0.0, 0.0));
|
||||
assert_relative_eq!(forces[3], Vector3::new(-0.5 * torque2, 0.5 * torque2, 0.0));
|
||||
assert_relative_eq!(forces[1], -forces[0] - forces[2]);
|
||||
assert_relative_eq!(
|
||||
state.get_potential_energy(),
|
||||
0.5 * 1.1 * PI / 6.0 * PI / 6.0 + 0.5 * 1.2 * PI / 4.0 * PI / 4.0
|
||||
);
|
||||
|
||||
forcefield.set_angle_parameters(0, 0, 1, 2, PI / 3.1, 1.3);
|
||||
forcefield.set_angle_parameters(1, 1, 2, 3, PI / 2.1, 1.4);
|
||||
forcefield.update_parameters_in_context(&mut context);
|
||||
|
||||
let state = context.get_state(StateType::Either);
|
||||
let forces = state.get_forces();
|
||||
let dtheta1 = (PI / 2.0) - (PI / 3.1);
|
||||
let dtheta2 = (3.0 * PI / 4.0) - (PI / 2.1);
|
||||
let torque1 = 1.3 * dtheta1;
|
||||
let torque2 = 1.4 * dtheta2;
|
||||
assert_relative_eq!(forces[0], Vector3::new(torque1, 0.0, 0.0));
|
||||
assert_relative_eq!(forces[3], Vector3::new(-0.5 * torque2, 0.5 * torque2, 0.0));
|
||||
assert_relative_eq!(forces[1], -forces[0] - forces[2]);
|
||||
assert_relative_eq!(
|
||||
state.get_potential_energy(),
|
||||
0.5 * 1.3 * dtheta1 * dtheta1 + 0.5 * 1.4 * dtheta2 * dtheta2
|
||||
);
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_harmonic_angle_force_with_periodic_boundary_conditions() {
|
||||
let mut system = System {};
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
system.set_default_periodic_box_vectors(
|
||||
Vector3::new(3.0, 0.0, 0.0),
|
||||
Vector3::new(0.0, 1.5, 0.0),
|
||||
Vector3::new(0.0, 0.0, 3.0),
|
||||
);
|
||||
|
||||
let integrator = VerletIntegrator { dt: 0.01 };
|
||||
let mut forcefield = HarmonicAngleForce {};
|
||||
forcefield.add_angle(0, 1, 2, PI / 3.0, 1.1);
|
||||
forcefield.set_periodic_boundary_conditions(true);
|
||||
|
||||
system.add_force(Box::new(forcefield));
|
||||
|
||||
let mut context = Context {
|
||||
system,
|
||||
integrator: Box::new(integrator),
|
||||
platform: Box::new(CPU),
|
||||
};
|
||||
|
||||
let mut positions = vec![Vector3::zeros(); 3];
|
||||
positions[0] = Vector3::new(0.0, 1.0, 0.0);
|
||||
positions[1] = Vector3::new(0.0, 0.0, 0.0);
|
||||
positions[2] = Vector3::new(1.0, 0.0, 0.0);
|
||||
context.set_positions(positions);
|
||||
|
||||
let state = context.get_state(StateType::Either);
|
||||
let forces = state.get_forces();
|
||||
|
||||
let torque = 1.1 * PI / 6.0;
|
||||
assert_relative_eq!(forces[0], Vector3::new(2.0 * torque, 0.0, 0.0));
|
||||
assert_relative_eq!(forces[2], Vector3::new(0.0, -torque, 0.0));
|
||||
|
||||
let energy = state.get_potential_energy();
|
||||
assert_relative_eq!(energy, 0.5 * 1.1 * (PI / 6.0) * (PI / 6.0));
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_harmonic_angle_force_parallel_computation() {
|
||||
// TODO: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
151
src/force/harmonic_bond_force.rs
Normal file
151
src/force/harmonic_bond_force.rs
Normal file
@@ -0,0 +1,151 @@
|
||||
use crate::context::Context;
|
||||
use crate::force::Force;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct HarmonicBondForce {}
|
||||
impl HarmonicBondForce {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn add_bond(&mut self, _particle1: usize, _particle2: usize, _length: f64, _k: f64) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_bond_parameters(
|
||||
&mut self,
|
||||
_particle1: usize,
|
||||
_particle2: usize,
|
||||
_length: f64,
|
||||
_k: f64,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
impl Force for HarmonicBondForce {
|
||||
fn update_parameters_in_context(&mut self, _context: &mut Context) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn set_periodic_boundary_conditions(&mut self, _status: bool) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn use_periodic_boundary_conditions(&self) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for HarmonicBondForce {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::HarmonicBondForce;
|
||||
use crate::context::Context;
|
||||
use crate::force::Force;
|
||||
use crate::integrator::VerletIntegrator;
|
||||
use crate::platform::CPU;
|
||||
use crate::state::StateType;
|
||||
use crate::system::System;
|
||||
use approx::assert_relative_eq;
|
||||
use nalgebra::Vector3;
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_harmonic_bond_force() {
|
||||
let mut system = System {};
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
let integrator = VerletIntegrator { dt: 0.01 };
|
||||
|
||||
let mut forcefield = HarmonicBondForce {};
|
||||
forcefield.add_bond(0, 1, 1.5, 0.8);
|
||||
forcefield.add_bond(1, 2, 1.2, 0.7);
|
||||
|
||||
system.add_force(Box::new(forcefield.clone()));
|
||||
|
||||
let mut context = Context {
|
||||
system,
|
||||
integrator: Box::new(integrator),
|
||||
platform: Box::new(CPU),
|
||||
};
|
||||
let mut positions = vec![Vector3::zeros(); 3];
|
||||
positions[0] = Vector3::new(0.0, 2.0, 0.0);
|
||||
positions[1] = Vector3::new(0.0, 0.0, 0.0);
|
||||
positions[2] = Vector3::new(1.0, 0.0, 0.0);
|
||||
context.set_positions(positions);
|
||||
|
||||
let state = context.get_state(StateType::Either);
|
||||
let forces = state.get_forces();
|
||||
assert_relative_eq!(forces[0], Vector3::new(0.0, -0.8 * 0.5, 0.0));
|
||||
assert_relative_eq!(forces[2], Vector3::new(0.7 * 0.2, 0.0, 0.0));
|
||||
assert_relative_eq!(forces[1], -forces[0] - forces[2]);
|
||||
|
||||
let energy = state.get_potential_energy();
|
||||
assert_relative_eq!(energy, 0.5 * 0.8 * 0.5 * 0.5 + 0.5 * 0.7 * 0.2 * 0.2);
|
||||
|
||||
forcefield.set_bond_parameters(0, 0, 1.6, 0.9);
|
||||
forcefield.set_bond_parameters(1, 1, 1.3, 0.8);
|
||||
forcefield.update_parameters_in_context(&mut context);
|
||||
|
||||
let state = context.get_state(StateType::Both);
|
||||
let forces = state.get_forces();
|
||||
assert_relative_eq!(forces[0], Vector3::new(0.0, -0.9 * 0.4, 0.0));
|
||||
assert_relative_eq!(forces[2], Vector3::new(0.8 * 0.3, 0.0, 0.0));
|
||||
assert_relative_eq!(forces[1], -forces[0] - forces[2]);
|
||||
|
||||
let energy = state.get_potential_energy();
|
||||
assert_relative_eq!(energy, 0.5 * 0.9 * 0.4 * 0.4 + 0.5 * 0.8 * 0.3 * 0.3);
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_harmonic_bond_force_with_periodic_boundary_conditions() {
|
||||
let mut system = System {};
|
||||
system.add_particle(1.0);
|
||||
system.add_particle(1.0);
|
||||
system.set_default_periodic_box_vectors(
|
||||
Vector3::new(3.0, 0.0, 0.0),
|
||||
Vector3::new(0.0, 3.0, 0.0),
|
||||
Vector3::new(0.0, 0.0, 3.0),
|
||||
);
|
||||
|
||||
let integrator = VerletIntegrator { dt: 0.01 };
|
||||
let mut forcefield = HarmonicBondForce {};
|
||||
forcefield.add_bond(0, 1, 1.2, 0.8);
|
||||
forcefield.set_periodic_boundary_conditions(true);
|
||||
|
||||
system.add_force(Box::new(forcefield));
|
||||
|
||||
let mut context = Context {
|
||||
system,
|
||||
integrator: Box::new(integrator),
|
||||
platform: Box::new(CPU),
|
||||
};
|
||||
|
||||
let mut positions = vec![Vector3::zeros(); 2];
|
||||
positions[0] = Vector3::new(0.0, 2.0, 0.0);
|
||||
positions[1] = Vector3::new(0.0, 0.0, 0.0);
|
||||
context.set_positions(positions);
|
||||
|
||||
let state = context.get_state(StateType::Both);
|
||||
let forces = state.get_forces();
|
||||
assert_relative_eq!(forces[0], Vector3::new(0.0, -0.8 * 0.2, 0.0));
|
||||
assert_relative_eq!(forces[1], Vector3::new(0.0, 0.8 * 0.2, 0.0));
|
||||
|
||||
let energy = state.get_potential_energy();
|
||||
assert_relative_eq!(energy, 0.5 * 0.8 * 0.2 * 0.2);
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_harmonic_bond_force_parallel_computation() {
|
||||
// TODO: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
15
src/force/mod.rs
Normal file
15
src/force/mod.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::context::Context;
|
||||
|
||||
pub trait Force: Debug {
|
||||
fn update_parameters_in_context(&mut self, context: &mut Context);
|
||||
fn set_periodic_boundary_conditions(&mut self, status: bool);
|
||||
fn use_periodic_boundary_conditions(&self) -> bool;
|
||||
}
|
||||
|
||||
pub mod harmonic_angle_force;
|
||||
pub use harmonic_angle_force::HarmonicAngleForce;
|
||||
|
||||
pub mod harmonic_bond_force;
|
||||
pub use harmonic_bond_force::HarmonicBondForce;
|
||||
6
src/integrator/mod.rs
Normal file
6
src/integrator/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
pub trait Integrator {}
|
||||
|
||||
pub struct VerletIntegrator {
|
||||
pub dt: f64,
|
||||
}
|
||||
impl Integrator for VerletIntegrator {}
|
||||
233
src/lib.rs
233
src/lib.rs
@@ -1,227 +1,8 @@
|
||||
pub mod context;
|
||||
pub mod force;
|
||||
pub mod platform;
|
||||
pub mod state;
|
||||
pub mod system;
|
||||
|
||||
|
||||
|
||||
pub mod system{
|
||||
use crate::force::Force;
|
||||
use crate::virtual_site::VirtualSite;
|
||||
|
||||
pub struct System{}
|
||||
impl System{
|
||||
pub fn add_particle(&mut self, mass: f32){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_num_particles(&self) -> usize{
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_particle_mass(&self, index: usize) -> f32{
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_particle_mass(&mut self, index: usize, mass: f32){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn is_virtual_site(&self, index: usize) -> bool{
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_virtual_site(&self, index: usize) -> Option<Box<dyn VirtualSite>>{
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_virtual_site(&mut self, index: usize, vsite: Option<Box<dyn VirtualSite>>){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn add_constraint(&mut self, p1: usize, p2: usize, dist: f32){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn remove_constraint(&mut self, index: usize){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_num_constraints(&self) -> usize{
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_constraint_parameters(&self, index: usize) -> (usize, usize, f32){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_constraint_parameters(&mut self, index: usize, p1: usize, p2: usize, dist: f32){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn add_force(&mut self, force: Box<dyn Force>){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn remove_force(&mut self, index: usize){
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_num_forces(&self) -> usize{
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_force(&self, index: usize) -> Box<dyn Force>{
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod force{
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub trait Force : Debug{}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct HarmonicAngleForce{}
|
||||
impl Force for HarmonicAngleForce{}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct HarmonicBondForce{}
|
||||
impl Force for HarmonicBondForce{}
|
||||
}
|
||||
|
||||
pub mod virtual_site{
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub trait VirtualSite : Debug{}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TwoParticleAverageSite{
|
||||
pub p1: usize,
|
||||
pub p2: usize,
|
||||
pub weight1: f32,
|
||||
pub weight2: f32,
|
||||
}
|
||||
impl TwoParticleAverageSite{
|
||||
pub fn new(p1: usize, p2: usize, weight1: f32, weight2: f32) -> Self{
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
impl VirtualSite for TwoParticleAverageSite{}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test{
|
||||
use crate::system::System;
|
||||
use crate::force::{HarmonicAngleForce, HarmonicBondForce};
|
||||
use crate::virtual_site::TwoParticleAverageSite;
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_particles(){
|
||||
let num_particles = 10;
|
||||
let mut system = System{};
|
||||
|
||||
for i in 0..num_particles{
|
||||
system.add_particle(1.0 + 0.1 * i as f32);
|
||||
}
|
||||
system.set_particle_mass(5, 100.0);
|
||||
assert_eq!(system.get_num_particles(), num_particles);
|
||||
|
||||
for i in 0..num_particles{
|
||||
let expected_mass = if i == 5 { 100.0 } else { 1.0 + 0.1 * i as f32 };
|
||||
assert_eq!(system.get_particle_mass(i), expected_mass);
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_constraints(){
|
||||
let num_particles = 10;
|
||||
let mut system = System{};
|
||||
|
||||
for i in 0..num_particles - 1{
|
||||
system.add_constraint(i, i + 1, 0.2 * i as f32);
|
||||
}
|
||||
system.remove_constraint(5);
|
||||
system.set_constraint_parameters(3, 0, 5, 99.0);
|
||||
assert_eq!(system.get_num_constraints(), num_particles - 2);
|
||||
|
||||
for i in 0..num_particles - 2{
|
||||
let (p1, p2, dist) = system.get_constraint_parameters(i);
|
||||
if i == 3 {
|
||||
assert_eq!(p1, 0);
|
||||
assert_eq!(p2, 5);
|
||||
assert_eq!(dist, 99.0);
|
||||
} else {
|
||||
let j = if i < 5 { i } else { i + 1 };
|
||||
assert_eq!(p1, j);
|
||||
assert_eq!(p2, j + 1);
|
||||
assert_eq!(dist, 0.2 * j as f32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_force(){
|
||||
let mut system = System{};
|
||||
let bonds = HarmonicBondForce{};
|
||||
system.add_force(Box::new(bonds));
|
||||
|
||||
let angles = HarmonicAngleForce{};
|
||||
system.add_force(Box::new(angles));
|
||||
|
||||
assert_eq!(system.get_num_forces(), 2);
|
||||
// Todo: Rust-OpenMM
|
||||
// assert_eq!(system.get_force(0), Box::new(bonds));
|
||||
// assert_eq!(system.get_force(1), Box::new(angles));
|
||||
|
||||
system.remove_force(0);
|
||||
assert_eq!(system.get_num_forces(), 1);
|
||||
// Todo: Rust-OpenMM
|
||||
// assert_eq!(system.get_force(0), Box::new(angles));
|
||||
}
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_virtual_site(){
|
||||
let mut system = System{};
|
||||
let num_particles = 10;
|
||||
for i in 0..num_particles{
|
||||
system.add_particle(1.0);
|
||||
assert!(!system.is_virtual_site(i));
|
||||
}
|
||||
|
||||
let vsite = TwoParticleAverageSite::new(2, 3, 0.4, 0.6);
|
||||
system.set_virtual_site(4, Some(Box::new(vsite)));
|
||||
for i in 0..num_particles{
|
||||
assert_eq!(system.is_virtual_site(i), i == 4);
|
||||
}
|
||||
// Todo: Rust-OpenMM
|
||||
// assert_eq!(system.get_virtual_site(4), Some(Box::new(vsite)));
|
||||
system.set_virtual_site(4, None);
|
||||
for i in 0..num_particles{
|
||||
assert!(!system.is_virtual_site(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod integrator;
|
||||
pub mod virtual_site;
|
||||
|
||||
7
src/platform/mod.rs
Normal file
7
src/platform/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
pub trait Platform {}
|
||||
|
||||
pub struct CPU;
|
||||
pub struct OpenCL;
|
||||
|
||||
impl Platform for CPU {}
|
||||
impl Platform for OpenCL {}
|
||||
24
src/state.rs
Normal file
24
src/state.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use nalgebra::Vector3;
|
||||
|
||||
pub enum StateType {
|
||||
Both,
|
||||
Either,
|
||||
Forces,
|
||||
Energy,
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
pub state_type: StateType,
|
||||
pub forces: Vec<Vector3<f64>>,
|
||||
pub energy: f64,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn get_forces(&self) -> &Vec<Vector3<f64>> {
|
||||
&self.forces
|
||||
}
|
||||
|
||||
pub fn get_potential_energy(&self) -> f64 {
|
||||
self.energy
|
||||
}
|
||||
}
|
||||
211
src/system.rs
Normal file
211
src/system.rs
Normal file
@@ -0,0 +1,211 @@
|
||||
use crate::force::Force;
|
||||
use crate::virtual_site::VirtualSite;
|
||||
use nalgebra::Vector3;
|
||||
pub struct System {}
|
||||
impl System {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn add_particle(&mut self, _mass: f32) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_num_particles(&self) -> usize {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_particle_mass(&self, _index: usize) -> f32 {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_particle_mass(&mut self, _index: usize, _mass: f32) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn is_virtual_site(&self, _index: usize) -> bool {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_virtual_site(&self, _index: usize) -> Option<Box<dyn VirtualSite>> {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_virtual_site(&mut self, _index: usize, _vsite: Option<Box<dyn VirtualSite>>) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn add_constraint(&mut self, _p1: usize, _p2: usize, _dist: f32) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn remove_constraint(&mut self, _index: usize) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_num_constraints(&self) -> usize {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_constraint_parameters(&self, _index: usize) -> (usize, usize, f32) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_constraint_parameters(&mut self, _index: usize, _p1: usize, _p2: usize, _dist: f32) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn add_force(&mut self, _force: Box<dyn Force>) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn remove_force(&mut self, _index: usize) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_num_forces(&self) -> usize {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_force(&self, _index: usize) -> Box<dyn Force> {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_default_periodic_box_vectors(
|
||||
&mut self,
|
||||
_a: Vector3<f32>,
|
||||
_b: Vector3<f32>,
|
||||
_c: Vector3<f32>,
|
||||
) {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn use_periodic_boundary_conditions(&self) -> bool {
|
||||
// Todo: Rust-OpenMM
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for System {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::force::{HarmonicAngleForce, HarmonicBondForce};
|
||||
use crate::system::System;
|
||||
use crate::virtual_site::TwoParticleAverageSite;
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_particles() {
|
||||
let num_particles = 10;
|
||||
let mut system = System {};
|
||||
|
||||
for i in 0..num_particles {
|
||||
system.add_particle(1.0 + 0.1 * i as f32);
|
||||
}
|
||||
system.set_particle_mass(5, 100.0);
|
||||
assert_eq!(system.get_num_particles(), num_particles);
|
||||
|
||||
for i in 0..num_particles {
|
||||
let expected_mass = if i == 5 { 100.0 } else { 1.0 + 0.1 * i as f32 };
|
||||
assert_eq!(system.get_particle_mass(i), expected_mass);
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_constraints() {
|
||||
let num_particles = 10;
|
||||
let mut system = System {};
|
||||
|
||||
for i in 0..num_particles - 1 {
|
||||
system.add_constraint(i, i + 1, 0.2 * i as f32);
|
||||
}
|
||||
system.remove_constraint(5);
|
||||
system.set_constraint_parameters(3, 0, 5, 99.0);
|
||||
assert_eq!(system.get_num_constraints(), num_particles - 2);
|
||||
|
||||
for i in 0..num_particles - 2 {
|
||||
let (p1, p2, dist) = system.get_constraint_parameters(i);
|
||||
if i == 3 {
|
||||
assert_eq!(p1, 0);
|
||||
assert_eq!(p2, 5);
|
||||
assert_eq!(dist, 99.0);
|
||||
} else {
|
||||
let j = if i < 5 { i } else { i + 1 };
|
||||
assert_eq!(p1, j);
|
||||
assert_eq!(p2, j + 1);
|
||||
assert_eq!(dist, 0.2 * j as f32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_force() {
|
||||
let mut system = System {};
|
||||
let bonds = HarmonicBondForce {};
|
||||
system.add_force(Box::new(bonds));
|
||||
|
||||
let angles = HarmonicAngleForce {};
|
||||
system.add_force(Box::new(angles));
|
||||
|
||||
assert_eq!(system.get_num_forces(), 2);
|
||||
// Todo: Rust-OpenMM
|
||||
// assert_eq!(system.get_force(0), Box::new(bonds));
|
||||
// assert_eq!(system.get_force(1), Box::new(angles));
|
||||
|
||||
system.remove_force(0);
|
||||
assert_eq!(system.get_num_forces(), 1);
|
||||
// Todo: Rust-OpenMM
|
||||
// assert_eq!(system.get_force(0), Box::new(angles));
|
||||
}
|
||||
|
||||
// Todo: Rust-OpenMM
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_system_virtual_site() {
|
||||
let mut system = System {};
|
||||
let num_particles = 10;
|
||||
for i in 0..num_particles {
|
||||
system.add_particle(1.0);
|
||||
assert!(!system.is_virtual_site(i));
|
||||
}
|
||||
|
||||
let vsite = TwoParticleAverageSite::new(2, 3, 0.4, 0.6);
|
||||
system.set_virtual_site(4, Some(Box::new(vsite)));
|
||||
for i in 0..num_particles {
|
||||
assert_eq!(system.is_virtual_site(i), i == 4);
|
||||
}
|
||||
// Todo: Rust-OpenMM
|
||||
// assert_eq!(system.get_virtual_site(4), Some(Box::new(vsite)));
|
||||
system.set_virtual_site(4, None);
|
||||
for i in 0..num_particles {
|
||||
assert!(!system.is_virtual_site(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/virtual_site.rs
Normal file
17
src/virtual_site.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub trait VirtualSite: Debug {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TwoParticleAverageSite {
|
||||
pub p1: usize,
|
||||
pub p2: usize,
|
||||
pub weight1: f32,
|
||||
pub weight2: f32,
|
||||
}
|
||||
impl TwoParticleAverageSite {
|
||||
pub fn new(_p1: usize, _p2: usize, _weight1: f32, _weight2: f32) -> Self {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
impl VirtualSite for TwoParticleAverageSite {}
|
||||
Reference in New Issue
Block a user