Ejemplo n.º 1
0
	def determineF(self,system):
		w2=self.hill.w**2
		N=system.natom
		self.localGPos=np.zeros((N,3))
		self.localVTens=np.zeros((3,3))
		if self.hill.id=='volume':
			cv=system.cell.volume
			g=-np.sum(self.H[:]*self.hill.h*(cv-self.B[:])/w2*np.exp(-(cv-self.B[:])**2/2./w2))
			self.localVTens=np.identity(3)*g*cv
			self.U=np.sum(self.H[:]*self.hill.h*np.exp(-(cv-self.B[:])**2/2./w2))
		elif self.hill.id=='cell':
			rvecs=system.cell.rvecs
			uc=UnitCell(np.array(rvecs))
        		abc,abg=uc.parameters
        		cv=abc[self.hill.atoms]
			g=np.zeros((3,3))
			g[self.hill.atoms,self.hill.atoms]=-np.sum(self.H[:]*self.hill.h*(cv-self.B[:])/w2*np.exp(-(cv-self.B[:])**2/2./w2))
			self.localVTens=np.dot(rvecs,np.dot(g,rvecs.T))/np.linalg.det(rvecs)**2
			self.U=np.sum(self.H[:]*self.hill.h*np.exp(-(cv-self.B[:])**2/2./w2))
		elif self.hill.id=='angle':
			cv,cvderiv=bend_angle(np.array([system.pos[self.hill.atoms[0],:],system.pos[self.hill.atoms[1],:],system.pos[self.hill.atoms[2],:]]),deriv=1)
			g=-np.sum(self.H[:]*self.hill.h*(cv-self.B[:])/w2*np.exp(-(cv-self.B[:])**2/2./w2))
			for i,a in enumerate(self.hill.atoms):
				self.localGPos[a,:]=g*cvderiv[i,:]
			self.U=np.sum(self.H[:]*self.hill.h*np.exp(-(cv-self.B[:])**2/2./w2))
		else:
			raise NotImplementedError
Ejemplo n.º 2
0
    def cart_to_zmat(self, coordinates):
        """Convert cartesian coordinates to ZMatrix format

           Argument:
             coordinates  --  Cartesian coordinates (numpy array Nx3)

           The coordinates must match with the graph that was used to initialize
           the ZMatrixGenerator object.
        """
        N = len(self.graph.numbers)
        if coordinates.shape != (N, 3):
            raise ValueError("The shape of the coordinates must be (%i, 3)" % N)
        result = numpy.zeros(N, dtype=self.dtype)
        for i in xrange(N):
            ref0 = self.old_index[i]
            rel1 = -1
            rel2 = -1
            rel3 = -1
            distance = 0
            angle = 0
            dihed = 0
            if i > 0:
                ref1 = self._get_new_ref([ref0])
                distance = numpy.linalg.norm(coordinates[ref0]-coordinates[ref1])
                rel1 = i - self.new_index[ref1]
            if i > 1:
                ref2 = self._get_new_ref([ref0, ref1])
                angle, = ic.bend_angle(coordinates[[ref0, ref1, ref2]])
                rel2 = i - self.new_index[ref2]
            if i > 2:
                ref3 = self._get_new_ref([ref0, ref1, ref2])
                dihed, = ic.dihed_angle(coordinates[[ref0, ref1, ref2, ref3]])
                rel3 = i - self.new_index[ref3]
            result[i] = (self.graph.numbers[i], distance, rel1, angle, rel2, dihed, rel3)
        return result
Ejemplo n.º 3
0
 def cart_to_zmat(self, coordinates):
     N = len(self.graph.numbers)
     result = numpy.zeros(N, dtype=self.dtype)
     for i in xrange(N):
         ref0 = self.old_index[i]
         rel1 = -1
         rel2 = -1
         rel3 = -1
         distance = 0
         angle = 0
         dihed = 0
         if i > 0:
             ref1 = self.get_new_ref([ref0])
             distance = numpy.linalg.norm(coordinates[ref0] -
                                          coordinates[ref1])
             rel1 = i - self.new_index[ref1]
         if i > 1:
             ref2 = self.get_new_ref([ref0, ref1])
             angle, = ic.bend_angle(coordinates[ref0], coordinates[ref1],
                                    coordinates[ref2])
             rel2 = i - self.new_index[ref2]
         if i > 2:
             ref3 = self.get_new_ref([ref0, ref1, ref2])
             dihed, = ic.dihed_angle(coordinates[ref0], coordinates[ref1],
                                     coordinates[ref2], coordinates[ref3])
             rel3 = i - self.new_index[ref3]
         result[i] = (self.graph.numbers[i], distance, rel1, angle, rel2,
                      dihed, rel3)
     return result
Ejemplo n.º 4
0
 def cart_to_zmat(self, coordinates):
     N = len(self.graph.numbers)
     result = numpy.zeros(N, dtype=self.dtype)
     for i in xrange(N):
         ref0 = self.old_index[i]
         rel1 = -1
         rel2 = -1
         rel3 = -1
         distance = 0
         angle = 0
         dihed = 0
         if i > 0:
             ref1 = self.get_new_ref([ref0])
             distance = numpy.linalg.norm(coordinates[ref0]-coordinates[ref1])
             rel1 = i - self.new_index[ref1]
         if i > 1:
             ref2 = self.get_new_ref([ref0, ref1])
             angle, = ic.bend_angle(coordinates[ref0], coordinates[ref1], coordinates[ref2])
             rel2 = i - self.new_index[ref2]
         if i > 2:
             ref3 = self.get_new_ref([ref0, ref1, ref2])
             dihed, = ic.dihed_angle(coordinates[ref0], coordinates[ref1], coordinates[ref2], coordinates[ref3])
             rel3 = i - self.new_index[ref3]
         result[i] = (self.graph.numbers[i], distance, rel1, angle, rel2, dihed, rel3)
     return result
Ejemplo n.º 5
0
	def determineCV(self,iterative):
		if self.hill.id=='volume':
			return iterative.ff.system.cell.volume		
		elif self.hill.id=='cell':
			uc=UnitCell(np.array(iterative.ff.system.cell.rvecs))
                        abc,abg=uc.parameters
                        return abc[self.hill.atoms]
		elif self.hill.id=='angle':
			return bend_angle(np.array([iterative.ff.system.pos[self.hill.atoms[0],:],iterative.ff.system.pos[self.hill.atoms[1],:],iterative.ff.system.pos[self.hill.atoms[2],:]]))[0]
		else:
			raise NotImplementedError
Ejemplo n.º 6
0
def get_bonds_angles(geometries, atoms):
    """
    This functions takes an array with the geometries, and a list with a group of atoms
    and returns the bond or angle evolution during the simulation

    """
    number_of_steps, number_of_atoms, _ = geometries.shape
    colvar = np.empty(number_of_steps)
    if len(atoms) == 2:
        for frame in range(number_of_steps):
            colvar[frame] = bond_length(geometries[frame, atoms])[0]
    elif len(atoms) == 3:
        for frame in range(number_of_steps):
            colvar[frame] = bend_angle(geometries[frame, atoms])[0]
    return colvar
Ejemplo n.º 7
0
    def cart_to_zmat(self, coordinates):
        """Convert cartesian coordinates to ZMatrix format

           Argument:
             coordinates  --  Cartesian coordinates (numpy array Nx3)

           The coordinates must match with the graph that was used to initialize
           the ZMatrixGenerator object.
        """
        N = len(self.graph.numbers)
        if coordinates.shape != (N, 3):
            raise ValueError("The shape of the coordinates must be (%i, 3)" %
                             N)
        result = np.zeros(N, dtype=self.dtype)
        for i in range(N):
            ref0 = self.old_index[i]
            rel1 = -1
            rel2 = -1
            rel3 = -1
            distance = 0
            angle = 0
            dihed = 0
            if i > 0:
                ref1 = self._get_new_ref([ref0])
                distance = np.linalg.norm(coordinates[ref0] -
                                          coordinates[ref1])
                rel1 = i - self.new_index[ref1]
            if i > 1:
                ref2 = self._get_new_ref([ref0, ref1])
                angle, = ic.bend_angle(coordinates[[ref0, ref1, ref2]])
                rel2 = i - self.new_index[ref2]
            if i > 2:
                ref3 = self._get_new_ref([ref0, ref1, ref2])
                dihed, = ic.dihed_angle(coordinates[[ref0, ref1, ref2, ref3]])
                rel3 = i - self.new_index[ref3]
            result[i] = (self.graph.numbers[i], distance, rel1, angle, rel2,
                         dihed, rel3)
        return result
Ejemplo n.º 8
0
 def angle(self, *atoms):
     return ic.bend_angle([self.coordinates[i]
                           for i in atoms])[0] / units.deg
Ejemplo n.º 9
0
 def angle(self, *atoms):
     return ic.bend_angle([self.coordinates[i]
                           for i in atoms])[0] / units.deg
Ejemplo n.º 10
0
def bend_angle(mol, i0, i1, i2):
    c = mol.coordinates
    return ic.bend_angle(c[i0], c[i1], c[i2])[0]
Ejemplo n.º 11
0
 def determine_ics_from_topology(self, stretch_pot_kind='harmonic', bend_pot_kind='harmonic'):
 #original
 # def determine_ics_from_topology(self):
 #SHLL end
     '''
         Method to generate IC instances corresponding to all ics
         present in the bonds, bends, dihedrals and opdists attributes.
     '''
     #SHLL 1508
     self.stretch_pot_kind = stretch_pot_kind
     self.bend_pot_kind = bend_pot_kind
     #SHLL end
     self.ics = {}
     def sort_ffatypes(ffatypes, kind=''):
         if kind != 'opdist':
             if ffatypes[0] < ffatypes[-1]:
                 return ffatypes
             elif ffatypes[0]==ffatypes[-1]:
                 if len(ffatypes)==4:
                     if ffatypes[1]<ffatypes[2]:
                         return ffatypes
                     else:
                         return ffatypes[::-1]
                 else:
                     return ffatypes
             else:
                 return ffatypes[::-1]
         else:
             result = sorted(ffatypes[:3])
             result.append(ffatypes[3])
             return result
     #Find bonds
     number = {}
     for bond in self.bonds:
         name = 'bond/'+'.'.join(sort_ffatypes([self.ffatypes[at] for at in bond]))
         if name not in number.keys():
             number[name] = 0
         else:
             number[name] += 1
         #SHLL 1508
         #-- unit of spf force constant
         if stretch_pot_kind.lower()=='spf':
             kunitstr='kjmol'
         else:
             kunitstr='kjmol/A**2'
         ic = IC(
             name+str(number[name]), bond, bond_length,
             qunit='A', kunit=kunitstr
             )
         #original
         # ic = IC(
         #     name+str(number[name]), bond, bond_length,
         #     qunit='A', kunit='kjmol/A**2'
         # )
         #SHLL end
         if name in self.ics.keys():
             self.ics[name].append(ic)
         else:
             self.ics[name] = [ic]
     #Find bends
     number = {}
     for bend in self.bends:
         name = 'angle/'+'.'.join(sort_ffatypes([self.ffatypes[at] for at in bend]))
         if name not in number.keys():
             number[name] = 0
         else:
             number[name] += 1
         #SHLL 1508
         #-- unit of harmcos force constant
         if bend_pot_kind.lower()=='harmcos':
             kunitstr='kjmol'
         else:
             kunitstr='kjmol/rad**2'
         ic = IC(
             name+str(number[name]), bend, bend_angle,
             qunit='deg', kunit=kunitstr
         )
         #original
         # ic = IC(
         #     name+str(number[name]), bend, bend_angle,
         #     qunit='deg', kunit='kjmol/rad**2'
         # )
         #SHLL end
         if name in self.ics.keys():
             self.ics[name].append(ic)
         else:
             self.ics[name] = [ic]
     #Find dihedrals
     number = {}
     for dihed in self.diheds:
         if bend_angle(self.ref.coords[dihed[0:3]], deriv=0)[0] > 175*deg \
         or bend_angle(self.ref.coords[dihed[1:4]], deriv=0)[0] > 175*deg:
             continue
         name = 'dihed/'+'.'.join(sort_ffatypes([self.ffatypes[at] for at in dihed]))
         if name not in number.keys():
             number[name] = 0
         else:
             number[name] += 1
         ic = IC(
             name+str(number[name]), dihed, dihed_angle,
             qunit='deg', kunit='kjmol'
         )
         if name in self.ics.keys():
             self.ics[name].append(ic)
         else:
             self.ics[name] = [ic]
     #Find out-of-plane distances
     number = {}
     for opdist in self.opdists:
         if bend_angle(self.ref.coords[opdist[0:3]], deriv=0)[0] > 175*deg \
         or bend_angle(self.ref.coords[opdist[0:3]], deriv=0)[0] < 5*deg:
             continue
         name = 'opdist/'+'.'.join(sort_ffatypes([self.ffatypes[at] for at in opdist], kind='opdist'))
         if name not in number.keys(): number[name] = 0
         else: number[name] += 1
         ic = IC(
             name+str(number[name]), opdist, opbend_dist,
             qunit='A', kunit='kjmol/A**2'
         )
         if name in self.ics.keys():
             self.ics[name].append(ic)
         else:
             self.ics[name] = [ic]
Ejemplo n.º 12
0
def bend_angle(mol, i0, i1, i2):
    c = mol.coordinates
    return ic.bend_angle(c[i0], c[i1], c[i2])[0]
Ejemplo n.º 13
0
    mol = Molecule.from_file(filename)

    # setup stuff
    mol.set_default_graph()
    mol.set_default_symbols()

    return mol


if __name__ == "__main__":
    # initialize molecule
    mol = setup("1IRA_R_B_clean.pdb")

    # all bonds of degree 3
    for bond in kth_bonds(mol, 3):
        # find the coordinates of the bonds
        bond_coor = list(map(lambda x: mol.coordinates[x], bond))

        # print symbols of bond and bond angle in degrees
        to_print = [bond]+symbolify(mol, bond)+[bend_angle(bond_coor)[0]/deg]
        pretty(to_print, "\t")

    # all bonds of degree 4
    for bond in kth_bonds(mol, 4):
        # find the coordinates of the bonds
        bond_coor = list(map(lambda x: mol.coordinates[x], bond))

        # print symbols of bond and dihed angle in degrees
        to_print = [bond]+symbolify(mol, bond)+[dihed_angle(bond_coor)[0]/deg]
        pretty(to_print, "\t")