Skip to content

Commit

Permalink
Switch to passing orientation in dynamic variable
Browse files Browse the repository at this point in the history
  • Loading branch information
meister committed Aug 11, 2024
1 parent 2c59345 commit 19332b6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 58 deletions.
9 changes: 2 additions & 7 deletions include/cando/kinematics/jumpJoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ namespace kinematics
bool fieldsp() const { return true; };
void fields(core::Record_sp node);
public:
core::T_sp _Orientation; // This is the stub for children
/*! JumpJoints can have unlimited numbers of children */
gc::Vec0< Joint_sp > _Children;
static JumpJoint_sp make(const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable, core::T_sp orientation );
static JumpJoint_sp make(const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable );
protected:
/*! Bonded atoms can have different numbers of children wrt JumpJoints */
virtual int _maxNumberOfChildren() const { return INT_MAX;};
Expand All @@ -68,15 +67,11 @@ namespace kinematics
virtual void _releaseAllChildren();

public:
JumpJoint_O(const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable, core::T_sp orientation );
JumpJoint_O(const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable );

/*! Empty ctor */
JumpJoint_O() {};

// Return the 'external' coordinate
CL_DEFMETHOD core::T_sp getOrientation() const { return this->_Orientation; };
CL_DEFMETHOD void setOrientation(core::T_sp orientation) { this->_Orientation = orientation; };

virtual core::Symbol_sp typeSymbol() const;

Stub getInputStub(chem::NVector_sp coords) const;
Expand Down
14 changes: 6 additions & 8 deletions src/kinematics/jumpJoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ SYMBOL_EXPORT_SC_(KinPkg,orientation_selfFrame);
SYMBOL_EXPORT_SC_(KinPkg,orientation_labFrame);
SYMBOL_EXPORT_SC_(KinPkg,orientation_transform);

JumpJoint_O::JumpJoint_O( const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable, core::T_sp orientation ) : Joint_O(atomId,name,atomTable) {
if (orientation.notnilp()) {
this->_Orientation = orientation;
};
JumpJoint_O::JumpJoint_O( const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable ) : Joint_O(atomId,name,atomTable) {
};

bool JumpJoint_O::definedp() const
Expand All @@ -54,13 +51,12 @@ bool JumpJoint_O::definedp() const
CL_LAMBDA(atom-id name atom-table);
CL_LISPIFY_NAME("make_JumpJoint");
CL_DEF_CLASS_METHOD
JumpJoint_sp JumpJoint_O::make(const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable, core::T_sp orientation ) {
return gctools::GC<JumpJoint_O>::allocate( atomId, name, atomTable, orientation );
JumpJoint_sp JumpJoint_O::make(const chem::AtomId& atomId, core::T_sp name, chem::AtomTable_sp atomTable ) {
return gctools::GC<JumpJoint_O>::allocate( atomId, name, atomTable );
}

void JumpJoint_O::fields(core::Record_sp node) {
node->field_if_not_empty(INTERN_(kw,children),this->_Children);
node->field(INTERN_(kw,orientation),this->_Orientation);
this->Base::fields(node);
}

Expand Down Expand Up @@ -138,7 +134,9 @@ void JumpJoint_O::_updateChildrenXyzCoords(chem::NVector_sp coords)
}

Matrix JumpJoint_O::transform() const {
Matrix m = gc::As<geom::OMatrix_sp>(core::eval::funcall(_sym_orientation_transform, this->_Orientation))->ref();
// Invoke kin:orientation-transform to return the transform
// for this jump-joint
Matrix m = gc::As<geom::OMatrix_sp>(core::eval::funcall(_sym_orientation_transform, this->asSmartPtr()))->ref();
return m;
}

Expand Down
8 changes: 2 additions & 6 deletions src/lisp/topology/conformation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ energy-function-factory - provide a function that takes an aggregate and returns
tune-energy-function - A function that takes the energy-function and an assembler and modifies the energy-function."
(unless (every (lambda (os) (typep os 'oligomer-shape)) oligomer-shapes)
(error "You must provide a list of oligomer-shapes"))
(let* ((full-orientations oligomer-shapes)
(aggregate (chem:make-aggregate :all))
(let* ((aggregate (chem:make-aggregate :all))
(monomer-positions (make-hash-table))
(oligomers (mapcar (lambda (oligomer-shape)
(oligomer oligomer-shape))
Expand Down Expand Up @@ -231,7 +230,6 @@ tune-energy-function - A function that takes the energy-function and an assemble
(energy-function (chem:make-energy-function :keep-interaction keep-interaction :matter aggregate))
(assembler (loop for oligomer-molecule in oligomer-molecules
for oligomer = (car oligomer-molecule)
for one-orientation in full-orientations
for molecule = (cdr oligomer-molecule)
for oligomer-space = (oligomer-space oligomer)
for foldamer = (foldamer oligomer-space)
Expand All @@ -248,8 +246,7 @@ tune-energy-function - A function that takes the energy-function and an assemble
monomer-positions
joint-tree
(chem:atom-table energy-function)
adjustments
one-orientation)))
adjustments)))
(put-atmolecule ataggregate atmolecule molecule-index))
finally (return (make-instance (if monomer-subset
'subset-assembler
Expand Down Expand Up @@ -325,7 +322,6 @@ tune-energy-function - A function that takes the energy-function and an assemble
monomer-positions
joint-tree
(chem:atom-table energy-function)
nil
nil)))
(put-atmolecule ataggregate atmolecule molecule-index))
finally (return (make-instance 'training-assembler
Expand Down
19 changes: 6 additions & 13 deletions src/lisp/topology/fold.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@
monomer-positions
joint-tree
atom-table
adjustments
orientation)
adjustments)
(let* ((ring-closing-monomer-map (make-hash-table))
(monomer-out-couplings (make-hash-table))
(atmolecule (make-instance 'atmolecule :name (chem:get-name molecule) :molecule molecule)))
Expand All @@ -157,7 +156,6 @@
nil ; parent-joint
atom-table
adjustments
orientation
)
#+(or)(make-ring-closing-connections oligomer monomer-positions molecule ring-closing-monomer-map)
atmolecule))
Expand Down Expand Up @@ -226,8 +224,7 @@
monomer-positions ; map of monomers to monomer-positions
parent-joint
atom-table
adjustments
orientation)
adjustments)
"Recursively build a atmolecule from an oligomer by linking together kin:atresidues"
(if prev-monomer
(let ((next-atresidue nil)
Expand Down Expand Up @@ -262,8 +259,7 @@
atmolecule-index
next-atresidue-index
atom-table
adjustments
orientation)))
adjustments)))
(setf (stereoisomer-name next-atresidue) (current-stereoisomer-name prev-monomer oligomer)
(topology next-atresidue) next-topology)
(when atresidue
Expand Down Expand Up @@ -295,8 +291,7 @@
monomer-positions
parent-joint
atom-table
adjustments
orientation)))
adjustments)))
(let* ((prev-monomer (root-monomer oligomer))
(next-atresidue nil)
(next-atresidue-index nil)
Expand Down Expand Up @@ -324,8 +319,7 @@
atmolecule-index
next-atresidue-index
atom-table
adjustments
orientation)))
adjustments)))
(setf (stereoisomer-name next-atresidue) (current-stereoisomer-name prev-monomer oligomer)
(topology next-atresidue) next-topology)
(when parent-atresidue
Expand Down Expand Up @@ -354,8 +348,7 @@
monomer-positions
nil ; parent-joint
atom-table
adjustments
orientation))))
adjustments))))

(defun describe-recursively (atresidue prefix stream)
(princ prefix stream)
Expand Down
14 changes: 2 additions & 12 deletions src/lisp/topology/joint-templates.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
res)))
index*3)))))

(defgeneric write-into-joint-tree (joint-template parent-joint atresidue atmolecule-index atresidue-index atom-table adjustments one-orientation monomer monomer-subset))
(defgeneric write-into-joint-tree (joint-template parent-joint atresidue atmolecule-index atresidue-index atom-table adjustments monomer monomer-subset))

(defmethod write-into-joint-tree ((joint-template t)
parent-joint
Expand All @@ -324,7 +324,6 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset)
(error "write-into-joint-tree - handle joint-template ~a" joint-template))

Expand All @@ -335,14 +334,11 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset)
(let* ((constitution-atoms-index (constitution-atoms-index joint-template))
(atom-name (atom-name joint-template))
(atomid (list atmolecule-index atresidue-index constitution-atoms-index))
(joint (if one-orientation
(kin:make-jump-joint atomid atom-name atom-table one-orientation)
(kin:make-jump-joint atomid atom-name atom-table (make-orientation)))))
(joint (kin:make-jump-joint atomid atom-name atom-table)))
(put-joint atresidue joint constitution-atoms-index)
(when parent-joint (kin:joint/add-child parent-joint joint))
joint))
Expand All @@ -354,7 +350,6 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset
)
(let* ((constitution-atoms-index (constitution-atoms-index joint-template))
Expand Down Expand Up @@ -394,7 +389,6 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset
)
(when (and monomer-subset (null parent-joint))
Expand Down Expand Up @@ -453,7 +447,6 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset
)
(if (and monomer-subset (null parent-joint))
Expand All @@ -473,7 +466,6 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset
)
(when (and monomer-subset (null parent-joint))
Expand All @@ -492,7 +484,6 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset
)
(if (and monomer-subset (null parent-joint))
Expand All @@ -515,7 +506,6 @@
atresidue-index
atom-table
adjustments
one-orientation
monomer monomer-subset
)
(if (and monomer-subset (null parent-joint))
Expand Down
13 changes: 4 additions & 9 deletions src/lisp/topology/joint-tree.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
atmolecule-index
atresidue-index
atom-table
adjustments
orientation)
adjustments)
(let ((joint (write-into-joint-tree joint-template
parent-joint
atresidue
atmolecule-index
atresidue-index
atom-table
adjustments
orientation
monomer monomer-subset)))
(loop for child-joint-template in (children joint-template)
do (recursively-write-into-atresidue monomer
Expand All @@ -47,8 +45,7 @@
atmolecule-index
atresidue-index
atom-table
adjustments
orientation))
adjustments))
joint))

(defun maybe-fill-atresidue (joint-tree
Expand All @@ -60,8 +57,7 @@
atmolecule-index
atresidue-index
atom-table
adjustments
orientation)
adjustments)
"Recursively build an atom-tree into the atresidues of an ataggregate.
This duplicates https://github.com/cando-developers/cando/blob/main/src/kinematics/pointTree.cc#L172
JointTree_O::recursivelyBuildMolecule
Expand All @@ -87,8 +83,7 @@ If (null parent-joint) then this is the root atresidue. "
atmolecule-index
atresidue-index
atom-table
adjustments
orientation)))
adjustments)))
(when (null parent-joint)
(if (null (gethash oligomer (root-map joint-tree)))
(setf (gethash oligomer (root-map joint-tree)) (list root-joint))
Expand Down
3 changes: 2 additions & 1 deletion src/lisp/topology/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@
#:make-indexes-into-rotamer-indexes
#:rotamer-indexes
#:indexes-into-rotamer-indexes
#:ensure-permissible-rotamers-equal))
#:ensure-permissible-rotamers-equal
#:with-orientation))

(defpackage #:topology.dag
(:use #:common-lisp)
Expand Down
14 changes: 12 additions & 2 deletions src/lisp/topology/shape.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,18 @@
collect rotamer-index))))
(format stream "~s ~s :rotamer-indexes ~s" (name obj) (rotamers-state obj) vec))))

(defmethod kin:orientation-transform ((oligomer-shape oligomer-shape))
(kin:orientation-transform (orientation oligomer-shape)))
(defvar *orientation*)

(defmethod kin:orientation-transform ((jump-joint kin:jump-joint))
(unless (boundp '*orientation*)
(error "~s must be bound for kin:orientation-transform to work" '*orientation*))
(kin:orientation-transform *orientation*))

(defmacro with-orientation ((orientation) &body body)
"Set the *orientation* dynamic variable so that external coordinate building can function"
`(let ((*orientation* ,orientation))
(progn
,@body)))

(defclass receptor-shape (oligomer-shape)
((aggregate :initarg :aggregate :accessor aggregate)
Expand Down

0 comments on commit 19332b6

Please sign in to comment.