simulate.py 4.22 KB
Newer Older
1
import os
2
3
import tempfile
from .coords import readArbdCoords, readAvgArbdCoords
4
5
6
7

arbd="/home/cmaffeo2/development/cuda/arbd.dbg/src/arbd" # reduced the mem footprint cause vmd
namd="/home/cmaffeo2/development/namd-bin/NAMD_Git-2017-07-06_Linux-x86_64-multicore-CUDA/namd2"

8
9
def multiresolution_simulation( model, output_name, 
                                job_id=None,
10
11
                                gpu = 0,
                                directory=None,
12
13
14
15
16
17
                                coarse_steps = 5e7,
                                fine_steps = 5e7,
                                coarse_output_period = 1e5,
                                fine_output_period = 1e5,
                                remove_long_bonds=False,
                                backbone_scale=1.0,
18
                            ):
19

20
    ## Round steps up to nearest multiple of output_period, plus 1
21
22
    coarse_steps = ((coarse_steps+coarse_output_period-1)//coarse_output_period)*coarse_output_period+1
    fine_steps = ((fine_steps+fine_output_period-1)//fine_output_period)*fine_output_period+1
23

24
25
26
27
    ret = None
    d_orig = os.getcwd()
    try:
        if directory is None:
28
29
            tmp = job_id if job_id is not None else output_name
            directory = tempfile.mkdtemp(prefix='origami-%s-' % tmp, dir='/dev/shm/')
30
31
32
33
34
35
36
37
38
        elif not os.path.exists(directory):
            os.makedirs(directory)
        os.chdir(directory)

        output_directory = "output"
        
        # TODO: add the output directory in to the readArbdCoords functions or make it an attribute of the model object 

        """ Coarse simulation """
39
        simargs = dict(timestep=200e-6, outputPeriod=coarse_output_period, gpu=gpu)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

        model._clear_beads()
        model._generate_bead_model( 5, 5, local_twist=False )

        if remove_long_bonds:
            output_prefix = "%s-0" % output_name
            full_output_prefix = "%s/%s" % (output_directory,output_prefix)
            ## TODO Remove long bonds
            model.simulate( outputPrefix = output_prefix, numSteps=0.05*coarse_steps, **simargs )
            coordinates = readArbdCoords('%s.0.restart' % full_output_prefix)
            output_prefix = "%s-1" % output_name
            model._update_segment_positions(coordinates)
            model.simulate( outputPrefix = output_prefix, numSteps=0.95*coarse_steps, **simargs )
        else:
            output_prefix = "%s-1" % output_name
            full_output_prefix = "%s/%s" % (output_directory,output_prefix)
            model.simulate( outputPrefix = output_prefix, numSteps=coarse_steps, **simargs )
        coordinates = readArbdCoords('%s.0.restart' % full_output_prefix)


        """ Fine simulation """ 
        output_prefix = "%s-2" % output_name
        full_output_prefix = "%s/%s" % (output_directory,output_prefix)
        simargs['timestep'] = 50e-6
64
        simargs['outputPeriod'] = fine_output_period
65
66
67
68
69
70
71
72
73
74
75
76
77
78
        model._update_segment_positions(coordinates)
        model._clear_beads()
        model._generate_bead_model( 1, 1, local_twist=True, escapable_twist=True )
        model.simulate( outputPrefix = output_prefix, numSteps=fine_steps, **simargs )
        coordinates = readAvgArbdCoords('%s.psf' % output_prefix,'%s.pdb' % output_prefix, '%s.0.dcd' % full_output_prefix, rmsdThreshold=1)


        """ Freeze twist """
        output_prefix = "%s-3" % output_name
        full_output_prefix = "%s/%s" % (output_directory,output_prefix)
        model._update_segment_positions(coordinates)
        model._clear_beads()
        model._generate_bead_model( 1, 1, local_twist=True, escapable_twist=False )
        model.simulate( outputPrefix = output_prefix, numSteps=fine_steps, **simargs )
cmaffeo2's avatar
cmaffeo2 committed
79
        coordinates = readAvgArbdCoords('%s.psf' % output_prefix,'%s.pdb' % output_prefix, '%s.0.dcd' % full_output_prefix )
80
81
82
83
84
85
86


        """ Atomic simulation """
        output_prefix = "%s-4" % output_name
        full_output_prefix = "%s/%s" % (output_directory,output_prefix)
        model._update_segment_positions(coordinates)
        model._clear_beads()
87
        model._generate_atomic_model(scale=backbone_scale)
88
89
90
91
92
93
94
95
96
97
        model.atomic_simulate( outputPrefix = output_prefix )

        ret = directory
        
    except:
        raise
    finally:
        os.chdir(d_orig)
        
    return ret