Calculate local elastic properties of consecutive overlapped DNA segments

        Calculate local elastic properties of consecutive overlapped DNA segments of length given by `span`.

        Parameters
        ----------
        bp : list
            List of two base-steps forming the global DNA segment.
            For example: with ``bp=[5, 50]``, 5-50 base-step segment will be considered.

        span : int
            Length of overlapping (local) DNA segments. It should be less than four.

        frameGap : int
            How many frames to skip for next time-frame. Lower the number, slower will be the calculation.

        helical : bool
            If ``helical=True``, elastic matrix for **helical base-step** parameters are calculated. Otherwise,
            by default, elastic matrix for **base-step** parameters are calculated.

        unit : str
            Unit of energy. Allowed units are: ``'kT', 'kJ/mol' and 'kcal/mol'``.

        err_type : str
            Error estimation by autocorrelation method ``err_type='acf'`` or
            block averaging method ``err_type='block'``

        tool : str
            GROMACS tool to calculate error. In older versions it is `g_analyze` while in
            newer versions (above 2016) it is `gmx analyze`.

        outFile : str
            Output file in csv format.

        Returns
        -------
        segments : list
            list of DNA segments for which local elastic properties was calculated.

        elasticities : OrderedDict
            A ordered dictionary of 1D arrays of shape (segments). The keys in dictionary are name of the elasticity in
            the same order as listed above.

        error : OrderedDict
            A ordered dictionary of 1D arrays of shape (segments). The keys in dictionary are name of the elasticity in
            the same order as listed above..

def calculateLocalElasticitySegments(self, bp, span=2, frameGap=None, helical=False, unit='kT',
                                         err_type='block', tool='gmx analyze', outFile=None):
        """Calculate local elastic properties of consecutive overlapped DNA segments

        Calculate local elastic properties of consecutive overlapped DNA segments of length given by `span`.

        Parameters
        ----------
        bp : list
            List of two base-steps forming the global DNA segment.
            For example: with ``bp=[5, 50]``, 5-50 base-step segment will be considered.

        span : int
            Length of overlapping (local) DNA segments. It should be less than four.

        frameGap : int
            How many frames to skip for next time-frame. Lower the number, slower will be the calculation.

        helical : bool
            If ``helical=True``, elastic matrix for **helical base-step** parameters are calculated. Otherwise,
            by default, elastic matrix for **base-step** parameters are calculated.

        unit : str
            Unit of energy. Allowed units are: ``'kT', 'kJ/mol' and 'kcal/mol'``.

        err_type : str
            Error estimation by autocorrelation method ``err_type='acf'`` or
            block averaging method ``err_type='block'``

        tool : str
            GROMACS tool to calculate error. In older versions it is `g_analyze` while in
            newer versions (above 2016) it is `gmx analyze`.

        outFile : str
            Output file in csv format.

        Returns
        -------
        segments : list
            list of DNA segments for which local elastic properties was calculated.

        elasticities : OrderedDict
            A ordered dictionary of 1D arrays of shape (segments). The keys in dictionary are name of the elasticity in
            the same order as listed above.

        error : OrderedDict
            A ordered dictionary of 1D arrays of shape (segments). The keys in dictionary are name of the elasticity in
            the same order as listed above..

        """
        if helical:
            props_name = helical_local_props_vector
        else:
            props_name = local_props_vector

        segments, errors, elasticities = [], OrderedDict(), OrderedDict()
        for name in props_name:
            elasticities[name] = []
            errors[name] = []

        for s in range(bp[0], bp[1]):
            if s+span-1 > bp[1]:
                break
            time, elasticity_t = self.getLocalElasticityByTime([s, s+span-1], frameGap=frameGap, helical=helical, unit=unit)
            error_t = dnaMD.get_error(time, list(elasticity_t.values()), len(props_name), err_type=err_type, tool=tool)
            for i in range(len(props_name)):
                esy_t = elasticity_t[props_name[i]][-1]           # only take last entry
                elasticities[props_name[i]].append(esy_t)
                errors[props_name[i]].append(error_t[i])
            segments.append('{0}-{1}'.format(s, s+span-1))

        # Write output file
        if outFile is not None:
            with open(outFile, 'w') as fout:
                fout.write('#bps')
                for name in props_name:
                    fout.write(', {0}, {0}-error'.format(name))
                fout.write('\n')
                for s in range(len(segments)):
                    fout.write('{0}'.format(segments[s]))
                    for name in props_name:
                        fout.write(', {0:.5f}, {1:.5f}'.format(elasticities[name][s], errors[name][s]))
                    fout.write('\n')

        return segments, elasticities, errors