Example #1
0
def tsladjust(nmtree, tslmin, lftargmax):
    """
    Adjust all muscles to have a maximum (dimensionless) operating length of lftargmax, 
    with a minimum tendon slack length of tslmin (in units of length e.g. meters)
    """
    for z in nmtree.NeuromechanicFile.Muscles.Muscle:
        MTL = z.MusculoTendonLength.x_
        LF0 = z.Model.OptimalFiberLength.x_
        TSL = z.Model.TendonSlackLength.x_
        PEN = z.Model.PennationAngle.x_
        mxMTL = MTL
        # max(MTL[:,ii]) # Get the maximum muscle length
        mnMTL = MTL
        # min(MTL[:,ii]) # Get the minimum muscle length
        lfmax = math.sqrt((mxMTL - TSL) ** 2 + (LF0 * math.sin(PEN)) ** 2)
        lfmin = math.sqrt((mnMTL - TSL) ** 2 + (LF0 * math.sin(PEN)) ** 2)

        # Solve for TSL to give lfmax/lf0 = 1.05; Minimum TSL = 5mm
        TSL = max(tslmin, mxMTL - math.sqrt(lftargmax ** 2 - math.sin(PEN) ** 2) * LF0)
        z.Model.TendonSlackLength.x_ = TSL

        # See what lfmax and lfmin will be
        lfmax = math.sqrt((mxMTL - TSL) ** 2 + (LF0 * math.sin(PEN)) ** 2)
        lfmin = math.sqrt((mnMTL - TSL) ** 2 + (LF0 * math.sin(PEN)) ** 2)
        nm.system_log(z.Name.x_ + ": [LFmax/LF0, LFmin/LF0] = [" + str(lfmax / LF0) + " , " + str(lfmin / LF0) + "]")
Example #2
0
def print(*arg):
    """ Prints whatever arg is to the neuromechanic logfile and log window """
    if type(arg) == type(" "):
        nm.system_log(arg)
    else:
        try:
            x = " ".join(map(str, arg))
        except:
            x = str(arg)
        nm.system_log(x)
Example #3
0
    def __getattr__(self, itemc):

        item = itemc.lower()
        if item == "x_":
            outvar = nm.tree_getvalue(self.__nodep)
            if type(outvar) == type([]):
                outvar = np.array(outvar)
            # if this is a list make it a numpy array
            return outvar
        elif item == "p_":
            return self.__nodep
        elif item == "c_":
            return self.__nodechildren
        elif item == "a_":
            return self.__nodeattributes

        elif item == "tag_":
            return self.__tag
        elif item == "xs_":
            outvar = self.x_
            return xmlstr(outvar)
        elif item == "print_":
            strng = "<" + self.__tag
            for x in self.__nodeattributes:
                # The node attributes dictionary is keyed with the attribute name and the value of the dictionary is a TreeList of length 1 element which is the Tree of the attribute itself;
                strng += " " + x + "=" + self.__nodeattributes[x].xs_
            strng += ">"
            for x in self.__nodechildren:
                z = self.__nodechildren[x].print_
                for zz in z:
                    strng += zz
            value = self.x_
            if value is not None:
                strng += self.xs_

            strng += "</" + self.__tag + ">"

            return strng
        elif item == "expointer_":
            return nm.tree_getnodeexternalpointer(self.__nodep)
        elif item == "enum1_":
            return nm.tree_getnodeenum1(self.__nodep)
        elif item == "list_":
            nm.system_log("Attributes:")
            for x in self.__nodeattributes:
                # The node attributes dictionary is keyed with the attribute name and the value of the dictionary is a TreeList of length 1 element which is the Tree of the attribute itself;
                nm.system_log("  " + x + "=" + self.__nodeattributes[x].xs_)
            nm.system_log("Children:")
            for x in self.__nodechildren:
                nm.system_log("  " + x + " (" + str(len(self.__nodechildren[x])) + ")")
            nm.system_log("Value:")
            nm.system_log("  " + self.xs_)
            nm.system_log("  ")

            # if this is a list make it a numpy array
            return None
        elif item in self.__nodechildren:
            return self.__nodechildren[item]
        elif item in self.__nodeattributes:
            return self.__nodeattributes[item]
            # return nm.tree_getvalue(self.__nodeattributes[item].__nodep);
        elif item in self.__nodecomments:
            return nm.tree_getvalue(self.__nodecomments[item].__nodep)
        else:
            return TreeList([])