From 90d72f062baf4930e1947716f690f440d066b0e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Mal=C3=BD?= <malym@ibt.cas.cz>
Date: Tue, 11 Jan 2022 17:16:00 +0100
Subject: [PATCH] Update API

---
 Types.inc | 67 +++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 53 insertions(+), 14 deletions(-)

diff --git a/Types.inc b/Types.inc
index 78f5e97..dcc406c 100644
--- a/Types.inc
+++ b/Types.inc
@@ -1,6 +1,6 @@
 <?php
 
-// vim: expandtab sw=4 ts=4 sts=4 :
+// vim: set sw=4 ts=4 sts=4 expandtab :
 
 /**
  * WebMMB PHP client
@@ -460,9 +460,9 @@ class Mobilizer
 }
 
 /**
- * Defines NtC class applicable to steps in a Compound
+ * Defines NtC conformation for a given step or range of steps
  */
-class NtC
+class NtCConformation
 {
     /**
      * Name of the chain
@@ -524,6 +524,45 @@ class NtC
     }
 }
 
+/**
+ * Defines NtCs configuration
+ */
+class NtCs
+{
+    /**
+     * Array of all applied NtC conformations
+     * @var NtCConformation[] $conformations
+     */
+    public array $conformations;
+    /**
+     * Global scale factor of the NtC forces
+     * @var flaot $force_scale_factor;
+     */
+    public float $force_scale_factor;
+
+    public function __construct(
+        array $conformations,
+        float $force_scale_factor
+    ) {
+        $this->conformations = $conformations;
+        $this->force_scale_factor = $force_scale_factor;
+    }
+
+    public static function fromArray(array $data)
+    {
+        try {
+            $obj = new self([], 0);
+
+            $obj->conformations = array_get('conformations', $data);
+            $obj->force_scale_factor = array_get('force_scale_factor', $data);
+
+            return $obj;
+        } catch (\TypeError $ex) {
+            throw new InvalidDataError($ex->getMessage());
+        }
+    }
+}
+
 /**
  * Defines residue number
  */
@@ -687,9 +726,9 @@ class StandardCommands extends Commands
     /**
      * NtCs to be applied.
      * This shall be set explicitly after the object is constructed.
-     * @var NtC[] $ntcs
+     * @var NtCs $ntcs
      */
-    public array $ntcs;
+    public object $ntcs;
     /**
      * Advanced job parametrers - currently unavailable
      * @var $adv_params
@@ -722,7 +761,7 @@ class StandardCommands extends Commands
         $this->compounds = [];
         $this->double_helices = [];
         $this->base_interactions = [];
-        $this->ntcs = [];
+        $this->ntcs = new NtCs([], 0);
         $this->mobilizers = [];
         $this->adv_params = new AdvParams();
         $this->set_default_MD_parameters = false;
@@ -743,9 +782,6 @@ class StandardCommands extends Commands
                 [ 'name' => 'base_interactions', 'initer' => function (array $data) {
                     return BaseInteraction::fromArray($data);
                 } ],
-                [ 'name' => 'ntcs', 'initer' => function (array $data) {
-                    return NtC::fromArray($data);
-                } ],
                 [ 'name' => 'mobilizers', 'initer' => function (array $data) {
                     return Mobilizer::fromArray($data);
                 } ]
@@ -753,6 +789,8 @@ class StandardCommands extends Commands
             foreach ($ARRAY_PROPS_INIT as $init) {
                 $obj->initializeArrayProperty($init['name'], $data, $init['initer']);
             }
+
+            $obj->ntcs = NtCs::fromArray(array_get('ntcs', $data));
             // TODO: adv_params once we start to support them
             $obj->set_default_MD_parameters = array_get('set_default_MD_parameters', $data);
 
@@ -794,9 +832,9 @@ class DensityFitCommands extends Commands
     /**
      * NtCs to be applied.
      * This shall be set explicitly after the object is constructed.
-     * @var NtC[] $ntcs
+     * @var NtCs $ntcs
      */
-    public array $ntcs = [];
+    public object $ntcs;
     /**
      * Whether to account for electrostatic and Lennard-Jones forces
      * @var bool $set_default_MD_parameters
@@ -834,6 +872,8 @@ class DensityFitCommands extends Commands
             throw new InvalidOperationError('Invalid name of density map file');
         }
 
+        $this->ntcs = new NtCs([], 0);
+
         $this->structure_file_name = $structure_file_name;
         $this->density_map_file_name = $density_map_file_name;
     }
@@ -847,9 +887,6 @@ class DensityFitCommands extends Commands
                 [ 'name' => 'compounds', 'initer' => function (array $data) {
                     return Compound::fromArray($data);
                 } ],
-                [ 'name' => 'ntcs', 'initer' => function (array $data) {
-                    return NtC::fromArray($data);
-                } ],
                 [ 'name' => 'mobilizers', 'initer' => function (array $data) {
                     return Mobilizer::fromArray($data);
                 } ]
@@ -857,6 +894,8 @@ class DensityFitCommands extends Commands
             foreach ($ARRAY_PROPS_INIT as $init) {
                 $obj->initializeArrayProperty($init['name'], $data, $init['initer']);
             }
+
+            $obj->ntcs = NtCs::fromArray(array_get('ntcs', $data));
             $obj->structure_file_name = array_get('structure_file_name', $data);
             $obj->density_map_file_name = array_get('density_map_file_name', $data);
             $obj->set_default_MD_parameters = array_get('set_default_MD_parameters', $data);
-- 
GitLab