Esempio n. 1
0
    def status(self,
               step,
               numberOfSteps,
               stepIncrement=1,
               mode=True,
               logEvery=10):
        """
        This method is used to log selection status.
 
        :Parameters:
            #. step (int): The current step number
            #. numberOfSteps (int): The total number of steps
            #. stepIncrement (int): The incrementation between one step and another
            #. mode (bool): if False no status logging
            #. logEvery (float): the frequency of status logging. its a percent number.
        """

        if not mode:
            return
        if step - 1 == -1:
            return
        actualPercent = int(float(step) / float(numberOfSteps) * 100)
        previousPercent = int(
            float(step - stepIncrement) / float(numberOfSteps) * 100)

        if actualPercent / logEvery != previousPercent / logEvery:
            Logger.info("%s%% completed. %s left out of %s" %
                        (actualPercent, numberOfSteps - step, numberOfSteps))
Esempio n. 2
0
 def __init__(self,
              trajectory,
              configurationsIndexes,
              cylinderAtomsIndexes,
              targetAtomsIndexes,
              axis=None,
              weighting="equal",
              histBin=1,
              *args,
              **kwargs):
     # set trajectory
     super(MeanSquareDisplacementInCylinder,
           self).__init__(trajectory, *args, **kwargs)
     # set configurations indexes
     self.configurationsIndexes = self.get_trajectory_indexes(
         configurationsIndexes)
     # set atoms indexes
     self.targetAtomsIndexes = self.get_atoms_indexes(targetAtomsIndexes)
     self.cylinderAtomsIndexes = self.get_atoms_indexes(
         cylinderAtomsIndexes)
     # set steps indexes
     self.numberOfSteps = len(self.targetAtomsIndexes)
     # set weighting
     assert is_element_property(weighting), Logger.error(
         "weighting '%s' don't exist in database" % weighting)
     self.weighting = weighting
     # set residency time histogram bin
     try:
         self.histBin = float(histBin)
     except:
         raise Logger.error(
             "histBin must be number convertible. %s is given." % histBin)
     assert self.histBin % 1 == 0, logger.error(
         "histBin must be integer. %s is given." % histBin)
     assert self.histBin > 0, logger.error(
         "histBin must be positive. %s is given." % histBin)
     assert self.histBin < len(self.configurationsIndexes), logger.error(
         "histBin must smaller than numberOfConfigurations")
     # initialize variables
     self.__initialize_variables__(axis)
     # initialize results
     self.__initialize_results__()
     # get cylinder centers, matrices, radii, length
     Logger.info(
         "%s --> initializing cylinder parameters along all configurations"
         % self.__class__.__name__)
     self.cylCenters, self.cylMatrices, self.cylRadii, self.cylLengths = self.__get_cylinder_properties__(
     )
Esempio n. 3
0
 def convert(self, types = None):
     """
     Converts to pdbParser
     """
     # read lines
     lines = self.get_lines()
     # get number of atoms
     self.info["number_of_records"] = self.__get_number_of_records__(lines)
     # get number of types
     self.info["number_of_types"] = self.__get_number_of_types__(lines)     
     # get simulation box vectors
     self.info["vectors"] = self.__get_box_vectors__(lines) 
     # set types names
     if types is None:
         Logger.info("types are not given. carbon element is considered for all types")
         self.info["types"] = [{"name":"c%s"%idx,"element":"c"} for idx in range(self.info["number_of_types"])]
     else:
         assert len(types) == self.info["number_of_types"], "types must be a list of length equal to the number of types"  
         for idx in range(self.info["number_of_types"]):
             if not isinstance(types[idx], dict):
                 assert is_element(types[idx]), "%s not found database elements"%types[idx]
                 types[idx] = {"name":types[idx], "element":types[idx]}
             assert types[idx].has_key("name"), "every type dictionary must have 'name' and 'element' keys" 
             assert types[idx].has_key("element"), "every type dictionary must have 'name' and 'element' keys" 
             if types[idx]["element"].lower() not in __atoms_database__.keys():
                 Logger.warr("type %r is not defined in database"%types[idx]["element"]) 
             else:
                 types[idx]["element"] = types[idx]["element"].lower()                
         self.info["types"] = types
     # get types records number     
     self.info["records_per_type"] = []        
     for idx in range(self.info["number_of_types"]):
         self.info["records_per_type"].append( self.__get_records_per_type__(lines, idx+1) )
     assert sum(self.info["records_per_type"]) == self.info["number_of_records"], "the sum of number of molecules in all types must be equal to number of ' molecules of all types'"
     # get coordinates
     fracCoord = self.__get_coordinates__(lines)
     assert fracCoord.shape ==(self.info["number_of_records"],3), "stored fractional coordinates must be equal to number of ' molecules of all types'"
     # calculate real coordinates
     realCoord = self.__calculate_real_coordinates__(fracCoord)
     # create pdb
     self.__create_pdb__(realCoord)
     return self
Esempio n. 4
0
    def status(self, step, totalSteps, logFrequency=10):
        """
        This method is used to log converting status.\n
 
        :Parameters:
            #. step (int): The current step number
            #. logFrequency (float): the frequency of status logging. its a percent number.
        """
        if not step:
            Logger.info("%s --> converting started" %
                        (self.__class__.__name__))
        elif step == totalSteps:
            Logger.info("%s --> converting finished" %
                        (self.__class__.__name__))
        else:
            actualPercent = int(float(step) / float(totalSteps) * 100)
            if self.__previousStep is not None:
                previousPercent = int(
                    float(self.__previousStep) / float(totalSteps) * 100)
            else:
                previousPercent = -1
            if actualPercent / logFrequency != previousPercent / logFrequency:
                Logger.info("%s --> %s%% completed. %s left out of %s" %
                            (self.__class__.__name__, actualPercent,
                             totalSteps - step, totalSteps))
        # update previous step
        self.__previousStep = step
 def __init__(self, pdb, dcd, indexes=None, format="charmm"):
     """
     Read new simulation trajectory 
     
     :Parameters:
         #. pdb (string): NAMD pdb file used as trajectory structure file
         #. dcd (string): NAMD DCD output file
         #. indexes (list): the configuration indexes to convert. None converts all configurations
         #. format (string): the known formats. only charmm and dcd are supported.  
     """
     # initialize converter
     super(DCDConverter, self).__init__()
     # log some info
     Logger.info("Converting NAMD trajectory")
     Logger.info("pdb file path: %s" % pdb)
     Logger.info("dcd file path: %s" % dcd)
     # check format
     assert isinstance(format, str), Logger.error("format must be a string")
     self.format = str(format).lower()
     assert self.format in (
         "charmm",
         "namd"), Logger.error("format must be either charmm or namd")
     # check indexes
     if indexes is not None:
         assert isinstance(
             indexes, (list, tuple, set, np.ndarray)), Logger.error(
                 "indexes must be a list of 3 integers [start, end, step]")
         indexes = [int(idx) for idx in sorted(set(indexes))]
         assert indexes[0] >= 0, Logger.error(
             "indexes start must be positive")
     self.indexes = indexes
     # check pdb file
     try:
         fd = open(pdb, 'r')
     except:
         raise Logger.error("cannot open pdb file")
     else:
         fd.close()
         self.pdb = pdb
     # check dcd file
     try:
         fd = open(dcd, 'r')
     except:
         raise Logger.error("cannot open dcd file")
     else:
         fd.close()
         self.dcd = dcd
     # create trajectory
     self.trajectory = None
Esempio n. 6
0
    def status(self, step, logFrequency=10):
        """
        This method is used to log analysis status.\n
 
        :Parameters:
            #. step (int): The current step number
            #. logFrequency (float): the frequency of status logging. its a percent number.
        """
        if not step:
            Logger.info("%s --> analysis started %s steps to go" %
                        (self.__class__.__name__, self.numberOfSteps))
        elif step == self.numberOfSteps:
            Logger.info("%s --> analysis steps finished" %
                        (self.__class__.__name__))
        else:
            actualPercent = int(float(step) / float(self.numberOfSteps) * 100)
            previousPercent = int(
                float(step - 1) / float(self.numberOfSteps) * 100)
            if actualPercent / logFrequency != previousPercent / logFrequency:
                Logger.info("%s --> %s%% completed. %s left out of %s" %
                            (self.__class__.__name__, actualPercent,
                             self.numberOfSteps - step, self.numberOfSteps))
from pdbParser import pdbParser
from pdbParser.Utilities.Simulate import Simulation

# import molecule
pdb = pdbParser(os.path.join(get_path("pdbparser"), "Data/WATER.pdb"))

# create simulation
sim = Simulation(pdb,
                 logStatus=False,
                 logExport=False,
                 numberOfSteps=100,
                 outputFrequency=1,
                 outputPath=tempfile.mktemp(".xyz"))

# initial parameters
Logger.info("minimizing 100 step with H-O-H angle %s and O-H bond %s" %
            (sim.__ANGLE__['h o h']['theta0'], sim.__BOND__['h o']['b0']))
sim.minimize_steepest_descent()

# change parameters to 120
sim.__ANGLE__['h o h']['theta0'] = 120
sim.set_angles_parameters()
sim.set_bonds_parameters()
Logger.info("minimizing 100 step with H-O-H angle %s and O-H bond %s" %
            (sim.__ANGLE__['h o h']['theta0'], sim.__BOND__['h o']['b0']))
sim.minimize_steepest_descent()

# change parameters to 120
sim.__BOND__['h o']['b0'] = 3
sim.set_angles_parameters()
sim.set_bonds_parameters()
Logger.info("minimizing 100 step with H-O-H angle %s and O-H bond %s" %
Esempio n. 8
0
    def finalize(self):
        """
        called once all the steps has been run.\n
        """
        # self.hbonds = [[[hIdx, shellIdx, shellTimeLimitsIdx, accIdx],[hIdx, shellIdx, shellTimeLimitsIdx,accIdx],...], ...  ]
        #                 ............first bond first shell..........,............first bond second shell2.......,....
        #                 ........................................first bond..........................................., .... second bond ...
        Logger.info("%s --> parsing and creating hydrogen bonds" %
                    (self.__class__.__name__))
        self.hbonds = [[]]

        def create_hbonds():
            for bond in self.hbonds:
                if not len(bond):
                    continue
                # check all bond time threshold
                if self.time[bond[-1][2][1]] - self.time[
                        bond[0][2][0]] < self.thresholdTime:
                    continue
                if self.bondStartAtCore and bond[0][1]:
                    continue
                self.results['hbonds_time'][bond[-1][2][1] -
                                            bond[0][2][0]] += 1
                self.results['number_of_hbonds'][
                    bond[0][2][0]:bond[-1][2][1]] += 1
                for shell in bond:
                    hIdx = shell[0]
                    shellIdx = shell[1]
                    shellTimeIdx = shell[2]
                    shellKey = self.shellsResultKeys[shellIdx]
                    time = shellTimeIdx[1] - shellTimeIdx[0]
                    # append 1 to hbonds time
                    self.results['hbonds_%s_time' % shellKey][time] += 1
                    # update number of hbonds
                    self.results['number_of_hbonds_%s' %
                                 shellKey][shellTimeIdx[0]:shellTimeIdx[1] +
                                           1] += 1
                    # calculate bond lengths histogram
                    hist, _ = np.histogram(
                        self.bondsDistances[hIdx,
                                            shellTimeIdx[0]:shellTimeIdx[1] +
                                            1], self.bins)
                    self.results['hbonds_%s_distribution' % shellKey] += hist

        def add_hbond(hIdx,
                      shellIdx,
                      shellTimeIdx,
                      thisAcceptor,
                      breakBond=False,
                      debugMessage=""):
            if not (shellTimeIdx[0] is None) and not (shellTimeIdx[1] is None):
                #if not (self.time[shellTimeIdx[1]]-self.time[shellTimeIdx[0]]<=self.hbondAllShellsTime[shellIdx]):
                #    print debugMessage
                #    print "last shell index: %s"%str(lastShellIdx)
                #    print "this shell index: %s"%str(thisShellIdx)
                #    print "saving shell index: %s"%str(shellIdx)
                #    print "stayed between %s"%str(shellTimeIdx)
                #    print "total time of %s while allowed time is %s"%(str(self.time[timeIdx]-self.time[shellTimeIdx[0]]), str(self.hbondAllShellsTime[shellIdx]))
                #    print '\n'
                # first or new hbond added to the same hydrogen atom
                if not len(self.hbonds[-1]):
                    self.hbonds[-1].append(
                        [hIdx, shellIdx, shellTimeIdx, thisAcceptor])
                # new hydrogen index
                elif self.hbonds[-1][-1][0] != hIdx:
                    self.hbonds.append(
                        [[hIdx, shellIdx, shellTimeIdx, thisAcceptor]])
                # new acceptor
                elif self.hbonds[-1][-1][3] != thisAcceptor:
                    self.hbonds.append(
                        [[hIdx, shellIdx, shellTimeIdx, thisAcceptor]])
                # not continuous shellTimeIdx
                elif self.hbonds[-1][-1][2][1] + 1 != shellTimeIdx[0]:
                    self.hbonds.append(
                        [[hIdx, shellIdx, shellTimeIdx, thisAcceptor]])
                else:
                    self.hbonds[-1].append(
                        [hIdx, shellIdx, shellTimeIdx, thisAcceptor])
                if breakBond:
                    self.hbonds.append([])

        def reset_shellTimeIdx_lowerAngleTime(thisDistance, thisAngle,
                                              thisTime):
            if self.bondStartAtCore and thisDistance > self.bondLength:
                shellTimeIdx = [None, None]
                lowerAngleTime = [None, None]
            elif self.bondStartWithinAngle and (
                    thisAngle < self.bondAngleLimits[0]
                    or thisAngle > self.bondAngleLimits[1]):
                shellTimeIdx = [None, None]
                lowerAngleTime = [None, None]
            else:
                shellTimeIdx = [timeIdx, timeIdx]
                # update bond angle time
                if thisAngle < self.bondAngleLimits[
                        0] or thisAngle > self.bondAngleLimits[1]:
                    if lowerAngleTime[0] is None:
                        lowerAngleTime = [thisTime, thisTime]
                    else:
                        lowerAngleTime[1] = thisTime
                else:
                    lowerAngleTime = [None, None]
            return shellTimeIdx, lowerAngleTime

        # create hydrogen bonds
        for hIdx in range(len(self.hydrogenAtomsIndexes)):
            # create shellsIndexes list
            shellsIndexes = []
            for timeIdx in range(len(self.configurationsIndexes)):
                thisDistance = self.bondsDistances[hIdx, timeIdx]
                if thisDistance == -1:
                    shellsIndexes.append(-1)
                else:
                    indexes = [
                        idx for idx in range(len(self.cumsumhbondAllShells))
                        if thisDistance <= self.cumsumhbondAllShells[idx]
                    ]
                    shellIdx = indexes[0]
                    shellsIndexes.append(shellIdx)
            # remove hfjumps
            if self.smoothHfJumps and len(shellsIndexes) >= 3:
                for timeIdx in range(1, len(shellsIndexes) - 1):
                    if self.bondsDistances[hIdx, timeIdx] == -1:
                        continue
                    if shellsIndexes[timeIdx - 1] == shellsIndexes[timeIdx +
                                                                   1]:
                        shellsIndexes[timeIdx] = shellsIndexes[timeIdx - 1]
                        self.bondsDistances[hIdx, timeIdx] = (
                            self.bondsDistances[hIdx, timeIdx - 1] +
                            self.bondsDistances[hIdx, timeIdx + 1]) / 2.
                    if self.acceptorsIndex[hIdx, timeIdx -
                                           1] == self.acceptorsIndex[hIdx,
                                                                     timeIdx +
                                                                     1]:
                        self.acceptorsIndex[
                            hIdx, timeIdx] = self.acceptorsIndex[hIdx,
                                                                 timeIdx - 1]
            # create hbonds
            shellTimeIdx = [None, None]
            lowerAngleTime = [None, None]
            for timeIdx in range(len(self.configurationsIndexes)):
                # get bond information
                thisShellIdx = shellsIndexes[timeIdx]
                thisAcceptor = self.acceptorsIndex[hIdx, timeIdx]
                thisAngle = self.bondsAngles[hIdx, timeIdx]
                thisTime = self.time[timeIdx]
                if timeIdx == 0:
                    lastShellIdx = thisShellIdx
                    lastAcceptor = thisAcceptor
                else:
                    lastAcceptor = self.acceptorsIndex[hIdx, timeIdx - 1]
                    lastShellIdx = shellsIndexes[timeIdx - 1]

                #################################################################################################
                ########################################## checking bond ########################################
                # check shell idx whether there is a bond or not
                if thisShellIdx == -1:
                    # add all valid bonds
                    add_hbond(hIdx,
                              lastShellIdx,
                              shellTimeIdx,
                              thisAcceptor,
                              breakBond=True,
                              debugMessage="no bond found")
                    # reset parameters
                    shellTimeIdx = [None, None]
                    lowerAngleTime = [None, None]
                    continue

                # new bond or after non-bond thisShellIdx = -1
                if shellTimeIdx[0] is None:
                    shellTimeIdx, lowerAngleTime = reset_shellTimeIdx_lowerAngleTime(
                        thisDistance, thisAngle, thisTime)
                    continue

                # check acceptors and break bond
                if thisAcceptor != lastAcceptor:
                    # add all valid bonds
                    add_hbond(hIdx,
                              lastShellIdx,
                              shellTimeIdx,
                              thisAcceptor,
                              breakBond=True,
                              debugMessage="different acceptor")
                    # reset parameters
                    shellTimeIdx, lowerAngleTime = reset_shellTimeIdx_lowerAngleTime(
                        thisDistance, thisAngle, thisTime)
                    continue

                # check bondAngle and break bond
                if thisAngle < self.bondAngleLimits[
                        0] or thisAngle > self.bondAngleLimits[1]:
                    if (lowerAngleTime[0] is not None):
                        if (thisTime - lowerAngleTime[0]
                            ) > self.belowAngleToleranceTime:
                            # add all valid bonds
                            add_hbond(hIdx,
                                      lastShellIdx,
                                      shellTimeIdx,
                                      thisAcceptor,
                                      breakBond=True,
                                      debugMessage="angle time")
                            # reset parameters
                            shellTimeIdx = [None, None]
                            lowerAngleTime = [None, None]
                            continue
                        else:
                            lowerAngleTime[1] = thisTime
                    else:
                        lowerAngleTime = [thisTime, thisTime]
                else:
                    lowerAngleTime = [None, None]

                # Bond change shell
                if thisShellIdx != lastShellIdx:
                    # add all valid bonds
                    add_hbond(hIdx,
                              lastShellIdx,
                              shellTimeIdx,
                              thisAcceptor,
                              breakBond=False,
                              debugMessage="jump to another shell")
                    # reset parameters
                    shellTimeIdx = [timeIdx, timeIdx]
                    continue

                # bond stay in same shell, check tolerance time
                elif thisTime - self.time[shellTimeIdx[
                        0]] <= self.hbondAllShellsTime[thisShellIdx]:
                    shellTimeIdx[1] = timeIdx
                    continue

                # bond break because of tolerance time in outer shell
                else:
                    # add all valid bonds
                    add_hbond(hIdx,
                              lastShellIdx,
                              shellTimeIdx,
                              thisAcceptor,
                              breakBond=True,
                              debugMessage="tolerance time violated")
                    # reset parameters
                    shellTimeIdx = [None, None]
                    lowerAngleTime = [None, None]
                    continue

            # final hbonds in hIdx
            add_hbond(hIdx,
                      lastShellIdx,
                      shellTimeIdx,
                      thisAcceptor,
                      breakBond=False)
        # create all registered hbond
        create_hbonds()

        # normalize and create the total
        for shellIdx in range(len(self.shellsResultKeys)):
            shellKey = self.shellsResultKeys[shellIdx]
            self.results['hbonds_%s_distribution' % shellKey] /= len(
                self.configurationsIndexes)
            self.results['hbonds_distribution'] += self.results[
                'hbonds_%s_distribution' % shellKey]

        # Hydrogen bonds mean life time
        nonzero = list(np.where(self.results['hbonds_time'])[0])
        nHbonds = [self.results['hbonds_time'][idx] for idx in nonzero]
        times = [self.results['time'][idx] for idx in nonzero]
        times = [times[idx] * nHbonds[idx] for idx in range(len(times))]
        if len(times):
            self.results['hBond_mean_life_time'] = np.array([np.sum(times)
                                                             ]) / len(times)
        else:
            self.results['hBond_mean_life_time'] = np.array([0.0])
Esempio n. 9
0
import numpy as np
from pdbParser.log import Logger
from pdbParser import pdbParser
from pdbParser.Utilities.Construct import AmorphousSystem
from pdbParser.Utilities.Database import __WATER__

# create pdbWATER
pdbWATER = pdbParser()
pdbWATER.records = __WATER__
pdbWATER.set_name("water")
Logger.info("Create water box")
pdbWATER = AmorphousSystem(pdbWATER,
                           density=0.25,
                           boxSize=np.array([10, 10,
                                             10])).construct().get_pdb()
pdbWATER.visualize()
Esempio n. 10
0
"""
Construct a graphene sheet in two orientations
"""
from pdbParser.log import Logger
from pdbParser import pdbParser
from pdbParser.Utilities.Geometry import translate
from pdbParser.Utilities.Construct import Sheet, Nanotube, MultipleWallNanotube

Logger.info("Constructing arm-chair sheet")
pdbGS_armchair = Sheet().construct().get_pdb()

Logger.info("Constructing zig-zag sheet")
pdbGS_zigzag = Sheet(orientation="zigzag").construct().pdb
translate(pdbGS_zigzag.indexes, pdbGS_zigzag, vector=[0, 0, 10])

Logger.info("Constructing carbon nanotube from scratch")
pdbCNT1 = Sheet(orientation="zigzag").construct().wrap().get_pdb()
translate(pdbCNT1.indexes, pdbCNT1, vector=[0, 40, 30])

Logger.info("constructing nanotube using appropriate class")
pdbCNT2 = Nanotube().construct().get_pdb()
translate(pdbCNT2.indexes, pdbCNT2, vector=[0, 10, 30])

Logger.info("constructing 5 walls multi-walled nanotube")
pdbMWNT = MultipleWallNanotube(
    wallsNumber=5,
    orientation=["armchair", "zig-zag", "zig-zag", "zig-zag",
                 "armchair"]).construct().get_pdb()
translate(pdbMWNT.indexes, pdbMWNT, vector=[0, 25, -40])

pdbALL = pdbGS_armchair
Esempio n. 11
0
                 stepTime=0.2,
                 numberOfSteps=10,
                 outputFrequency=1,
                 exportInitialConfiguration=True,
                 outputPath=tempfile.mktemp(".xyz"))
# remove all bonded interactions
sim.bonds_indexes = []
sim.angles_indexes = []
sim.dihedrals_indexes = []
sim.nBondsThreshold = [[], []]
# setting charges to 0
sim.atomsCharge = [0, 0]

# initial parameters
Logger.info(
    "minimizing %s steps at %s fm per step, with atoms charge %s, VDW forces push atoms to equilibrium distance %s"
    % (sim.numberOfSteps, sim.timeStep, sim.atomsCharge,
       2 * sim.__LJ__['h']['rmin/2']))
sim.minimize_steepest_descent()

# add charges and change stepTime
sim.atomsCharge = [0.15, 0.15]
sim.stepTime = 0.02
sim.exportInitialConfiguration = False

# re-minimize parameters
Logger.info(
    "minimizing %s steps at %s fm per step, with atoms charge %s, VDW forces push atoms to equilibrium distance %s"
    % (sim.numberOfSteps, sim.timeStep, sim.atomsCharge,
       2 * sim.__LJ__['h']['rmin/2']))
sim.minimize_steepest_descent()
Esempio n. 12
0
sim.bonds_indexes = []
sim.angles_indexes = []
sim.lennardJones_eps *= 0
sim.atomsCharge *= 0

# initial parameters
sim.__DIHEDRAL__["c c c c"] = {
    1.0: {
        'delta': 40.0,
        'n': 1.0,
        'kchi': 3.6375696
    }
}
sim.set_dihedrals_parameters()
Logger.info(
    "minimizing %s steps at %s fm per step, with all terms suppressed but dihedral %s"
    % (sim.numberOfSteps, sim.timeStep, sim.__DIHEDRAL__["c c c c"]))
sim.minimize_steepest_descent()

sim.exportInitialConfiguration = False

# initial parameters
sim.__DIHEDRAL__["c c c c"] = {
    1.0: {
        'delta': 120.0,
        'n': 1.0,
        'kchi': 3.6375696
    }
}
sim.set_dihedrals_parameters()
Logger.info(
Esempio n. 13
0
"""
Construct a graphene sheet in two orientations
"""
import os

from pdbParser.Utilities.Collection import get_path
from pdbParser.log import Logger
from pdbParser import pdbParser
from pdbParser.Utilities.Connectivity import Connectivity
from pdbParser.Utilities.Modify import reset_atom_name

Logger.info("reading SDBS molecule")
pdb = pdbParser(
    os.path.join(get_path("pdbparser"), "Data/connectivityTestMolecule.pdb"))

connectivity = Connectivity(pdb)

# bonds
Logger.info("calculating bonds")
connectivity.calculate_bonds()
bonds = connectivity.get_bonds(key="atom_name")
print "BONDS:"
print "======"
for idx in range(len(bonds[0])):
    print "%6s" % bonds[0][idx], ' = ', bonds[1][idx]
#connectivity.export_bonds('lol.psf')

# angles
Logger.info("calculating angles")
connectivity.calculate_angles()
angles = connectivity.get_angles(key="atom_name")
Esempio n. 14
0
import os
import numpy as np

from pdbParser.log import Logger
from pdbParser import pdbParser
from pdbParser.Utilities.Collection import get_path
from pdbParser.Utilities.Selection import NanotubeSelection
from pdbParser.Utilities.Information import get_models_records_indexes_by_records_indexes, get_records_indexes_in_attribute_values
from pdbParser.Utilities.Modify import *
from pdbParser.Utilities.Geometry import get_principal_axis, translate, orient

# read pdb
pdbCNT = pdbParser(
    os.path.join(get_path("pdbparser"), "Data/nanotubeWaterNAGMA.pdb"))

Logger.info("Define models")
# define models
define_models_by_records_attribute_value(pdbCNT.indexes, pdbCNT)

Logger.info("Getting nanotube indexes")
# get CNT indexes
cntIndexes = get_records_indexes_in_attribute_values(pdbCNT.indexes, pdbCNT,
                                                     "residue_name", "CNT")

Logger.info("Create selection")
# create selection
sel = NanotubeSelection(pdbCNT, nanotubeIndexes=cntIndexes).select()

Logger.info("Get models inside nanotube")
# construct models out of residues
indexes = get_models_records_indexes_by_records_indexes(
Esempio n. 15
0
sim.nBondsThreshold = [[] for ids in pdb.indexes]
sim.angles_indexes = []
sim.dihedrals_indexes = []
sim.atomsCharge *= 0

# minimize energy
#Logger.info("minimization at %s fm per step" % (sim.timeStep) ) 
#sim.outputFrequency = 1
#sim.minimize_steepest_descent(99)

# equilibration
sim.exportInitialConfiguration = True
sim.outputFrequency = 1
sim.logExport = True
sim.timeStep = 0.1
Logger.info("equilibration at %s fm per step" % (sim.timeStep) ) 
sim.simulate(100)

# production
sim.exportInitialConfiguration = False
sim.outputFrequency = 1
sim.logExport = True
sim.timeStep = 1
Logger.info("production at %s fm per step" % (sim.timeStep) ) 
sim.simulate(3000, initializeVelocities = False)


# visualize molecule
sim.visualize_trajectory(sim.outputPath)

Esempio n. 16
0
"""
In this test, an SDS molecule is loaded
several records manipulations, translation, rotation, orientation, ... are tested
"""
# standard distribution imports
import os

# pdbParser imports
from pdbParser.Utilities.Collection import get_path
from pdbParser.log import Logger
from pdbParser.pdbParser import pdbParser
from pdbParser.Utilities.Geometry import *

pdbRESULT = pdbParser()

Logger.info("loading sds molecule ...")
pdbSDS = pdbParser(os.path.join(get_path("pdbparser"), "Data", "SDS.pdb"))
INDEXES = range(len(pdbSDS.records))
# get molecule axis
sdsAxis = get_axis(INDEXES, pdbSDS)
## translate to positive quadrant
atomToOriginIndex = get_closest_to_origin(INDEXES, pdbSDS)
atom = pdbSDS.records[atomToOriginIndex]
[minX, minY,
 minZ] = [atom['coordinates_x'], atom['coordinates_y'], atom['coordinates_z']]
translate(INDEXES, pdbSDS, [-1.1 * minX, -1.1 * minY, -1.1 * minZ])

Logger.info("orient molecule along [1,0,0] ...")
orient(axis=[1, 0, 0], indexes=INDEXES, pdb=pdbSDS, records_axis=sdsAxis)
sdsAxis = [1, 0, 0]
pdbRESULT.concatenate(pdbSDS)
Esempio n. 17
0
# pdbParser imports
from pdbParser.Utilities.Collection import get_path
from pdbParser import pdbParser
from pdbParser.log import Logger
from pdbParser.Utilities.Construct import AmorphousSystem, Micelle
from pdbParser.Utilities.Geometry import get_satisfactory_records_indexes, translate
from pdbParser.Utilities.Modify import delete_records_and_models_records

from pdbParser.Utilities.Database import __WATER__

# create pdbWATER
pdbWATER = pdbParser()
pdbWATER.records = __WATER__
pdbWATER.set_name("water")

Logger.info("Create water box")
pdbWATER = AmorphousSystem(pdbWATER, density = 0.5).construct().get_pdb()
pdbWATERhollow = pdbWATER.get_copy()

# make sphere
Logger.info("Create a water sphere of 15A radius")
sphereIndexes = get_satisfactory_records_indexes(pdbWATER.indexes, pdbWATER, "np.sqrt(x**2 + y**2 + z**2) >= 15")
delete_records_and_models_records(sphereIndexes, pdbWATER)

# make hollow
Logger.info("Remove a water sphere of 15A radius")
hollowIndexes = get_satisfactory_records_indexes(pdbWATERhollow.indexes, pdbWATERhollow, "np.sqrt(x**2 + y**2 + z**2) <= 15")
delete_records_and_models_records(hollowIndexes, pdbWATERhollow)

# translate hollow
translate(pdbWATERhollow.indexes, pdbWATERhollow, vector =[60,0,0])