Exemplo n.º 1
0
def create_engine():
    # create engine
    ENGINE = Engine(path=None)
    ENGINE.set_pdb(pdbPath)
    # initialize constraints
    B_CONSTRAINT   = BondConstraint()
    BA_CONSTRAINT  = BondsAngleConstraint()
    IA_CONSTRAINT  = ImproperAngleConstraint()
    # add constraints
    ENGINE.add_constraints([B_CONSTRAINT])
    B_CONSTRAINT.create_bonds_by_definition( bondsDefinition={"THF": [('O' ,'C1' , 1.20, 1.70),
                                                                      ('O' ,'C4' , 1.20, 1.70),
                                                                      ('C1','C2' , 1.25, 1.90),
                                                                      ('C2','C3' , 1.25, 1.90),
                                                                      ('C3','C4' , 1.25, 1.90),
                                                                      ('C1','H11', 0.88, 1.16),('C1','H12', 0.88, 1.16),
                                                                      ('C2','H21', 0.88, 1.16),('C2','H22', 0.88, 1.16),
                                                                      ('C3','H31', 0.88, 1.16),('C3','H32', 0.88, 1.16),
                                                                      ('C4','H41', 0.88, 1.16),('C4','H42', 0.88, 1.16)] })
    ENGINE.add_constraints([BA_CONSTRAINT])
    BA_CONSTRAINT.create_angles_by_definition( anglesDefinition={"THF": [ ('O'  ,'C1' ,'C4' , 105, 125),
                                                                          ('C1' ,'O'  ,'C2' , 100, 120),
                                                                          ('C4' ,'O'  ,'C3' , 100, 120),
                                                                          ('C2' ,'C1' ,'C3' , 95 , 115),
                                                                          ('C3' ,'C2' ,'C4' , 95 , 115),
                                                                          # H-C-H angle
                                                                          ('C1' ,'H11','H12', 98 , 118),
                                                                          ('C2' ,'H21','H22', 98 , 118),
                                                                          ('C3' ,'H31','H32', 98 , 118),
                                                                          ('C4' ,'H41','H42', 98 , 118),
                                                                          # H-C-O angle
                                                                          ('C1' ,'H11','O'  , 100, 120),
                                                                          ('C1' ,'H12','O'  , 100, 120),
                                                                          ('C4' ,'H41','O'  , 100, 120),
                                                                          ('C4' ,'H42','O'  , 100, 120),                                                                           
                                                                          # H-C-C
                                                                          ('C1' ,'H11','C2' , 103, 123),
                                                                          ('C1' ,'H12','C2' , 103, 123),
                                                                          ('C2' ,'H21','C1' , 103, 123),
                                                                          ('C2' ,'H21','C3' , 103, 123),
                                                                          ('C2' ,'H22','C1' , 103, 123),
                                                                          ('C2' ,'H22','C3' , 103, 123),
                                                                          ('C3' ,'H31','C2' , 103, 123),
                                                                          ('C3' ,'H31','C4' , 103, 123),
                                                                          ('C3' ,'H32','C2' , 103, 123),
                                                                          ('C3' ,'H32','C4' , 103, 123),
                                                                          ('C4' ,'H41','C3' , 103, 123),
                                                                          ('C4' ,'H42','C3' , 103, 123) ] })
    ENGINE.add_constraints([IA_CONSTRAINT])
    IA_CONSTRAINT.create_angles_by_definition( anglesDefinition={"THF": [ ('C2','O','C1','C4', -15, 15),
                                                                          ('C3','O','C1','C4', -15, 15) ] })
    # initialize constraints data
    ENGINE.initialize_used_constraints()
    # set moves generators
    # set all move generators to Translation with a maximum amplutide of 0.3 A
    [g.set_move_generator(TranslationGenerator(amplitude=0.3)) for g in ENGINE.groups]
    # set randomly 25% of the translation amplitude to 10A
    [g.set_move_generator(TranslationGenerator(amplitude=10.)) for g in ENGINE.groups if np.random.random()>0.25]
    # return engine
    return ENGINE
Exemplo n.º 2
0
INTRA_STYLES = [r[0] + r[1] for r in itertools.product(['--'], colors)]
INTRA_STYLES = [r[0] + r[1] for r in itertools.product(markers, INTRA_STYLES)]
INTER_STYLES = [r[0] + r[1] for r in itertools.product(['-'], colors)]
INTER_STYLES = [r[0] + r[1] for r in itertools.product(markers, INTER_STYLES)]

trajectories = ["atomsTraj.xyz", "exploreTraj.xyz"]
pdbPath = "CO2.pdb"
expDataPath = "Xrays.gr"

# create engine
ENGINE = Engine(path=None)
ENGINE.set_pdb(pdbPath)
PDF_CONSTRAINT = PairDistributionConstraint(experimentalData=expDataPath,
                                            weighting="atomicNumber")
ENGINE.add_constraints([PDF_CONSTRAINT])
ENGINE.initialize_used_constraints()
ENGINE.set_chi_square()


def create_figure(PDF, show=False, savePath=None):
    # get output
    output = PDF.get_constraint_value()
    # create figure
    FIG = plt.figure()
    FIG.patch.set_facecolor('white')
    grid = gridspec.GridSpec(nrows=2, ncols=2)
    grid.update(left=0.05, right=0.95, wspace=0.05)
    totalAx = plt.subplot(grid[0, :])
    lowRAx = plt.subplot(grid[1, 0])
    highRAx = plt.subplot(grid[1, 1])
    # set axis ticks
Exemplo n.º 3
0
    params = {'rmin':0., 'rmax':None, 'dr':0.5,
              'qmin':0.0001, 'qmax':0.6, 'dq':0.005,
              'updateFreq':1000}
    PDF_CONSTRAINT.set_shape_function_parameters(params)
    ENGINE.add_constraints([PDF_CONSTRAINT])
    # Intermolecular constraint
    EMD_CONSTRAINT = InterMolecularDistanceConstraint()
    ENGINE.add_constraints([EMD_CONSTRAINT])
    EMD_CONSTRAINT.set_type_definition("element")
    EMD_CONSTRAINT.set_pairs_distance([('Si','Si',1.75), ('O','O',1.10), ('Si','O',1.30)])
    # coordination number constraint
    ACNC_CONSTRAINT = AtomicCoordinationNumberConstraint()
    ENGINE.add_constraints([ACNC_CONSTRAINT])
    ACNC_CONSTRAINT.set_coordination_number_definition( coordNumDef=[('Si','Si',1.8,2.8,3,6), ])
    # initialize constraints
    _ = ENGINE.initialize_used_constraints()
    # set number density
    ENGINE.set_number_density(.0125)
    # save engine
    ENGINE.save()
else:
    ENGINE = ENGINE.load(engineFilePath)
    # get constraints
    PDF_CONSTRAINT, EMD_CONSTRAINT, ACNC_CONSTRAINT = ENGINE.constraints



# add multiframe
if not ENGINE.is_frame(multiframe):
    ENGINE.add_frame({'name':multiframe, 'frames_name':numberOfFrames})
    for sf in ENGINE.frames[multiframe]['frames_name']:
Exemplo n.º 4
0
def run_engine(PDF=True,
               IMD=True,
               B=True,
               BA=True,
               IA=True,
               molecular=True,
               nsteps=10000,
               ncores=1):
    ENGINE = Engine(path=None)
    ENGINE.set_pdb(pdbPath)
    # create experimental constraints
    if PDF:
        C = PairDistributionConstraint(experimentalData=expPath,
                                       weighting="atomicNumber")
        ENGINE.add_constraints(C)
    # create and define molecular constraints
    if IMD:
        C = InterMolecularDistanceConstraint(defaultDistance=1.5)
        ENGINE.add_constraints(C)
    if B:
        C = BondConstraint()
        ENGINE.add_constraints(C)
        C.create_bonds_by_definition(
            bondsDefinition={
                "THF": [('O', 'C1', 1.29,
                         1.70), ('O', 'C4', 1.29,
                                 1.70), ('C1', 'C2', 1.29,
                                         1.70), ('C2', 'C3', 1.29,
                                                 1.70), ('C3', 'C4', 1.29,
                                                         1.70),
                        ('C1', 'H11', 0.58,
                         1.15), ('C1', 'H12', 0.58,
                                 1.15), ('C2', 'H21', 0.58,
                                         1.15), ('C2', 'H22', 0.58, 1.15),
                        ('C3', 'H31', 0.58,
                         1.15), ('C3', 'H32', 0.58,
                                 1.15), ('C4', 'H41', 0.58,
                                         1.15), ('C4', 'H42', 0.58, 1.15)]
            })
    if BA:
        C = BondsAngleConstraint()
        ENGINE.add_constraints(C)
        C.create_angles_by_definition(
            anglesDefinition={
                "THF": [
                    ('O', 'C1', 'C4', 95, 135),
                    ('C1', 'O', 'C2', 95, 135),
                    ('C4', 'O', 'C3', 95, 135),
                    ('C2', 'C1', 'C3', 90, 120),
                    ('C3', 'C2', 'C4', 90, 120),
                    # H-C-H angle
                    ('C1', 'H11', 'H12', 95, 125),
                    ('C2', 'H21', 'H22', 95, 125),
                    ('C3', 'H31', 'H32', 95, 125),
                    ('C4', 'H41', 'H42', 95, 125),
                    # H-C-O angle
                    ('C1', 'H11', 'O', 100, 120),
                    ('C1', 'H12', 'O', 100, 120),
                    ('C4', 'H41', 'O', 100, 120),
                    ('C4', 'H42', 'O', 100, 120),
                    # H-C-C
                    ('C1', 'H11', 'C2', 80, 123),
                    ('C1', 'H12', 'C2', 80, 123),
                    ('C2', 'H21', 'C1', 80, 123),
                    ('C2', 'H21', 'C3', 80, 123),
                    ('C2', 'H22', 'C1', 80, 123),
                    ('C2', 'H22', 'C3', 80, 123),
                    ('C3', 'H31', 'C2', 80, 123),
                    ('C3', 'H31', 'C4', 80, 123),
                    ('C3', 'H32', 'C2', 80, 123),
                    ('C3', 'H32', 'C4', 80, 123),
                    ('C4', 'H41', 'C3', 80, 123),
                    ('C4', 'H42', 'C3', 80, 123)
                ]
            })
    if IA:
        C = ImproperAngleConstraint()
        ENGINE.add_constraints(C)
        C.create_angles_by_definition(
            anglesDefinition={
                "THF": [('C2', 'O', 'C1', 'C4', -15,
                         15), ('C3', 'O', 'C1', 'C4', -15, 15)]
            })
    # initialize constraints data
    ENGINE.initialize_used_constraints()
    # run engine
    if molecular:
        ENGINE.set_groups_as_molecules()
        print 'molecular, %s atoms, %s steps, %2s cores' % (
            ENGINE.numberOfAtoms, nsteps, ncores),
        tic = time.time()
        ENGINE.run(numberOfSteps=nsteps,
                   saveFrequency=2 * nsteps,
                   restartPdb=None,
                   ncores=ncores)
        elapsed = float(time.time() - tic) / float(nsteps)
        print ' -- > %s seconds per step' % (elapsed, )
    else:
        ENGINE.set_groups_as_atoms()
        print 'atomic   , %s atoms, %s steps, %2s cores' % (
            ENGINE.numberOfAtoms, nsteps, ncores),
        tic = time.time()
        ENGINE.run(numberOfSteps=nsteps,
                   saveFrequency=2 * nsteps,
                   restartPdb=None,
                   ncores=ncores)
        elapsed = float(time.time() - tic) / float(nsteps)
        print ' -- > %s seconds per step' % (elapsed, )
        # return elapsed time
    return elapsed