fjc_polymer_model.py 5.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- coding: utf-8 -*-
## Test with `python -m arbdmodel.hps_polymer_model`

import numpy as np
import sys


## Local imports
from . import ArbdModel, ParticleType, PointParticle, Group, get_resource_path    
from .abstract_polymer import PolymerSection, AbstractPolymerGroup
from .interactions import NonbondedScheme, HarmonicBond, HarmonicPotential
from .coords import quaternion_to_matrix


"""Define particle types"""
type_ = ParticleType("X",
                     damping_coefficient = 40.9,
                     mass=120
)

## Bonded potentials
class FjcNonbonded(NonbondedScheme):
    def __init__(self, resolution=0.1, rMin=0):
        NonbondedScheme.__init__(self, typesA=None, typesB=None, resolution=resolution, rMin=rMin)

    def potential(self, r, typeA, typeB):
        """ Constant force excluded volume """
        force = 10              # kcal_mol/AA
        radius = 6
        
        u = np.zeros(r.shape)
        # s = r < 2*radius
        # u[s] = (2*radius - r[s]) * force            
        return u

class FjcBeadsFromPolymer(Group):

    def __init__(self, polymer, sequence=None, 
                 rest_length = 3.8, spring_constant = 25,
                 **kwargs):

        # if sequence is None:
        #     raise NotImplementedError
        #     # ... set random sequence

        self.polymer = polymer
        self.sequence = sequence
        self.spring_constant = 25
        self.rest_length = 3.8

        for prop in ('segname','chain'):
            if prop not in kwargs:
                # import pdb
                # pdb.set_trace()
                try:
                    self.__dict__[prop] = polymer.__dict__[prop]
                except:
                    pass

        # if len(sequence) != polymer.num_monomers:
        #     raise ValueError("Length of sequence does not match length of polymer")
        Group.__init__(self, **kwargs)
        

    def _clear_beads(self):
        ...
        
    def _generate_beads(self):
        # beads = self.children
        nb = self.polymer.num_monomers
        
        for i in range(nb):
            c = self.polymer.monomer_index_to_contour(i)
            r = self.polymer.contour_to_position(c)

            bead = PointParticle(type_, r,
                                 resid = i+1)
            self.add(bead)

        ## Two consecutive nts 
        for i in range(len(self.children)-1):
            b1 = self.children[i]
            b2 = self.children[i+1]
            """ units "10 kJ/N_A" kcal_mol """
            bond = HarmonicBond(k = self.spring_constant,
                                r0 = self.rest_length,
                                rRange = (0,500),
                                resolution = 0.01,
                                maxForce = 50)
            self.add_bond( i=b1, j=b2, bond = bond, exclude=True )

class FjcModel(ArbdModel):
    def __init__(self, polymers,
                 sequences = None,
                 rest_length = 3.8,
                 spring_constant = 25,
                 damping_coefficient = 40.9,
                 DEBUG=False,
                 **kwargs):

        """ 
        [damping_coefficient]: ns
        """

        print("WARNING: diffusion coefficient arbitrarily set to 100 AA**2/ns in FjcModel")
        
        kwargs['timestep'] = 50e-6
        kwargs['cutoff'] = 10

        if 'decompPeriod' not in kwargs:
            kwargs['decompPeriod'] = 100000

        """ Assign sequences """
        if sequences is None:
            # raise NotImplementedError("HpsModel must be provided a sequences argument")
            sequences = [None for i in range(len(polymers))]

        self.polymer_group = AbstractPolymerGroup(polymers)
        self.sequences = sequences
        self.rest_length = rest_length
        self.spring_constant = spring_constant
        ArbdModel.__init__(self, [], **kwargs)

        """ Update type diffusion coefficients """
        self.set_damping_coefficient( damping_coefficient )

        """ Set up nonbonded interactions """
        nonbonded = FjcNonbonded()
        self.useNonbondedScheme( nonbonded, typeA=type_, typeB=type_ )
                
        """ Generate beads """
        self.generate_beads()

    def update_splines(self, coords):
        i = 0
        for p,c in zip(self.polymer_group.polymers,self.children):
            n = len(c.children)
            p.set_splines(np.linspace(0,1,n), coords[i:i+n])
            i += n

        self.clear_all()
        self.generate_beads()
        ## TODO Apply restraints, etc

    def generate_beads(self):
        self.peptides = [FjcBeadsFromPolymer(p,s, rest_length = self.rest_length,
                                             spring_constant = self.spring_constant )
                         for p,s in zip(self.polymer_group.polymers,self.sequences)]

        for s in self.peptides:
            self.add(s)
            s._generate_beads()

    def set_damping_coefficient(self, damping_coefficient):
        for t in [type_]:
            t.damping_coefficient = damping_coefficient
            # t.diffusivity = 831447.2 * temperature / (t.mass * damping_coefficient)

if __name__ == "__main__":
    pass