pub struct RegionRestraint<R: Region>(pub R);Expand description
Wraps a Region as a soft-penalty AtomRestraint with quadratic
exterior penalty:
penalty(x) = scale2 * max(0, signed_distance(x))²Gradient uses the analytic chain rule
2 * scale2 * max(0, d) * ∂d/∂x, where ∂d/∂x comes from
Region::signed_distance_grad.
§Example
use molpack::region::{InsideSphereRegion, RegionExt};
use molpack::{RegionRestraint, AtomRestraint};
let shell = InsideSphereRegion::new([0.0; 3], 10.0)
.and(InsideSphereRegion::new([0.0; 3], 5.0).not());
let restraint = RegionRestraint(shell);
// At x=(7,0,0) the shell is satisfied → f == 0
assert_eq!(restraint.f(&[7.0, 0.0, 0.0], 1.0, 1.0), 0.0);
// At x=(15,0,0) we are outside the outer sphere → f > 0
assert!(restraint.f(&[15.0, 0.0, 0.0], 1.0, 1.0) > 0.0);Tuple Fields§
§0: RTrait Implementations§
Source§impl<R: Region + 'static> AtomRestraint for RegionRestraint<R>
impl<R: Region + 'static> AtomRestraint for RegionRestraint<R>
Source§impl<R: Clone + Region> Clone for RegionRestraint<R>
impl<R: Clone + Region> Clone for RegionRestraint<R>
Source§fn clone(&self) -> RegionRestraint<R>
fn clone(&self) -> RegionRestraint<R>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<R: Copy + Region> Copy for RegionRestraint<R>
Auto Trait Implementations§
impl<R> Freeze for RegionRestraint<R>where
R: Freeze,
impl<R> RefUnwindSafe for RegionRestraint<R>where
R: RefUnwindSafe,
impl<R> Send for RegionRestraint<R>
impl<R> Sync for RegionRestraint<R>
impl<R> Unpin for RegionRestraint<R>where
R: Unpin,
impl<R> UnsafeUnpin for RegionRestraint<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for RegionRestraint<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more