def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12) for dih in range(len(self.instance)-4): #do not include hydrogen atom constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) elif step < 22: for dih in range(len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) release.append(constraint) fvals = [2.0,1.4,1.3,1.8,1.3] val1 = geometry.new_bond_length(self.species,self.instance[0],self.instance[-2],step-11,10,fvals[0],geom) constraint1 = [self.instance[0] + 1,self.instance[-2] + 1,val1] change.append(constraint1) val2 = geometry.new_bond_length(self.species,self.instance[0],self.instance[1],step-11,10,fvals[1],geom) constraint2 = [self.instance[0] + 1,self.instance[1] + 1,val2] change.append(constraint2) val3 = geometry.new_bond_length(self.species,self.instance[1],self.instance[-1],step-11,10,fvals[2],geom) constraint3 = [self.instance[1] + 1,self.instance[-1] + 1,val3] change.append(constraint3) val4 = geometry.new_bond_length(self.species,self.instance[0],self.instance[-1],step-11,10,fvals[3],geom) constraint4 = [self.instance[0] + 1,self.instance[-1] + 1,val4] change.append(constraint4) val5 = geometry.new_bond_length(self.species,self.instance[-1],self.instance[-2],step-11,10,fvals[4],geom) constraint5 = [self.instance[-1] + 1,self.instance[-2] + 1,val5] change.append(constraint5) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: fval = [1.67,2.2,1.9] if self.species.atom[self.instance[0]] == 'H': fval = [1.7,1.09,2.2] if self.species.atom[self.instance[2]] == 'H': fval = [2.2,1.09,1.7] if self.species.atom[self.instance[0]] == 'O' or self.species.atom[self.instance[2]] == 'O': fval[1] = 1.8 val = geometry.new_bond_length(self.species,self.instance[0],self.instance[1],step+1,12,fval[0],geom) constraint = [self.instance[0] + 1,self.instance[1] + 1,val] change.append(constraint) val = geometry.new_bond_length(self.species,self.instance[1],self.instance[2],step+1,12,fval[1],geom) constraint = [self.instance[1] + 1,self.instance[2] + 1,val] change.append(constraint) val = geometry.new_bond_length(self.species,self.instance[2],self.instance[0],step+1,12,fval[2],geom) constraint = [self.instance[2] + 1,self.instance[0] + 1,val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self, step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i + 1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i + 1, j + 1]) if step < 12: final_dist = [2.0, 1.45, 1.4, 1.9] for i in range(len(self.instance)): if i == len(self.instance) - 1: j = 0 else: j = i + 1 val = geometry.new_bond_length(self.species, self.instance[i], self.instance[j], step + 1, 12, final_dist[i], geom) constraint = [self.instance[i] + 1, self.instance[j] + 1, val] change.append(constraint) f_dist = 1.3 val = geometry.new_bond_length(self.species, self.instance[1], self.instance[3], step + 1, 12, f_dist, geom) constraint = [self.instance[1] + 1, self.instance[3] + 1, val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i, fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: final_dist = [2.0, 1.45, 1.4, 1.9] for i in range(len(self.instance)): if i == len(self.instance) - 1: j = 0 else: j = i+1 val = geometry.new_bond_length(self.species,self.instance[i],self.instance[j],step + 1,12,final_dist[i],geom) constraint = [self.instance[i] + 1,self.instance[j] + 1,val] change.append(constraint) f_dist = 1.3 val = geometry.new_bond_length(self.species,self.instance[1],self.instance[3],step + 1,12,f_dist,geom) constraint = [self.instance[1] + 1,self.instance[3] + 1,val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def set_bond(self, a, b, val, change, step=None, stmax=None, findist=None, geom=None): if step is not None: val = geometry.new_bond_length(self.species, self.instance[a], self.instance[b], step, stmax, findist, geom) constraint = [self.instance[a] + 1, self.instance[b] + 1, val] change.append(constraint)
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] #~ if step < self.max_step - 1: #~ # fix all the bond lengths #~ for i in range(self.species.natom - 1): #~ for j in range(i+1, self.species.natom): #~ if self.species.bond[i][j] > 0: #~ fix.append([i+1,j+1]) if step < self.max_step: for fval in self.fvals: ndist = geometry.new_bond_length(self.species, fval[0], fval[1], step, self.max_step-1, fval[2], geom) constraint = [fval[0] + 1, fval[1] + 1, ndist] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def testNewBondLength(self): """ Test the calculation of new bond length necessary for the update """ smi = 'CCCC' mol = StationaryPoint(smi, 0, 1, smiles=smi) mol.characterize() ati = 0 atj = 1 step_nr = 1 # This corresponds to the first bond length update # there are 12 steps done in total, this means that the bond # length should be changed by 1/10 of the total change total_nr_of_steps = 10 # final bond length we are shooting for after 10 updates final_val = 2.0 # initial bond length ini = np.linalg.norm(mol.geom[ati] - mol.geom[atj]) # this is the new bond length one step cal = geometry.new_bond_length(mol, ati, atj, step_nr, total_nr_of_steps, final_val) exp = ini + (final_val - ini) / 10 warn = 'Dihedral update is not correct: ' warn += 'expected {}, calculated {}'.format(exp, cal) self.assertEqual(exp, cal, msg=warn)
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12) for dih in range(len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) elif step < 22: for dih in range(len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) release.append(constraint) fval = [2.0,1.3,2.0,2.0] if self.species.atom[self.instance[-1]] == 'H': fval[2] = 1.35 fval[3] = 1.35 val = geometry.new_bond_length(self.species,self.instance[0],self.instance[1],step - 11,10,fval[0],geom) constraint = [self.instance[0] + 1,self.instance[1] + 1,val] change.append(constraint) val = geometry.new_bond_length(self.species,self.instance[1],self.instance[2],step - 11,10,fval[1],geom) constraint = [self.instance[1] + 1,self.instance[2] + 1,val] change.append(constraint) val = geometry.new_bond_length(self.species,self.instance[2],self.instance[3],step - 11,10,fval[2],geom) constraint = [self.instance[2] + 1,self.instance[3] + 1,val] change.append(constraint) val = geometry.new_bond_length(self.species,self.instance[3],self.instance[0],step - 11,10,fval[3],geom) constraint = [self.instance[3] + 1,self.instance[0] + 1,val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self, step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i + 1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i + 1, j + 1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12) for dih in range(len(self.instance) - 3): constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) elif step < 22: for dih in range(len(self.instance) - 3): constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) release.append(constraint) fval = [2.0, 1.45, 2.0, 2.0] if self.species.atom[self.instance[0]] == 'H': fval[0] = 1.3 fval[3] = 1.3 val = geometry.new_bond_length(self.species, self.instance[0], self.instance[1], step - 11, 10, fval[0], geom) constraint = [self.instance[0] + 1, self.instance[1] + 1, val] change.append(constraint) val = geometry.new_bond_length(self.species, self.instance[1], self.instance[2], step - 11, 10, fval[1], geom) constraint = [self.instance[1] + 1, self.instance[2] + 1, val] change.append(constraint) val = geometry.new_bond_length(self.species, self.instance[2], self.instance[3], step - 11, 10, fval[2], geom) constraint = [self.instance[2] + 1, self.instance[3] + 1, val] change.append(constraint) val = geometry.new_bond_length(self.species, self.instance[3], self.instance[0], step - 11, 10, fval[3], geom) constraint = [self.instance[3] + 1, self.instance[0] + 1, val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i, fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step == 0: # verify if the radical atom has more than one neighbor and # change the dihedral to 90 degrees in that case neigh = [i for i,ni in enumerate(self.species.bond[self.instance[0]]) if ni > 0] if len(neigh) > 1: for ni in neigh: if not ni in self.instance: change.append([ni + 1, self.instance[0] + 1, self.instance[1] + 1, self.instance[2] + 1, 90.]) break if step < 12: final_dist = 1.42 if self.species.atom[self.instance[0]] == 'C' and self.species.atom[self.instance[1]] == 'C' and self.species.atom[self.instance[2]] == 'C': final_dist = 2.20 if self.species.atom[self.instance[0]] == 'C' and self.species.atom[self.instance[1]] == 'C' and self.species.atom[self.instance[2]] == 'H': final_dist = 1.79 if self.species.atom[self.instance[0]] == 'C' and self.species.atom[self.instance[1]] == 'C' and self.species.atom[self.instance[2]] == 'O': final_dist = 2.04 if self.species.atom[self.instance[0]] == 'O' and self.species.atom[self.instance[1]] == 'C' and self.species.atom[self.instance[2]] == 'C': final_dist = 2.12 if self.species.atom[self.instance[0]] == 'O' and self.species.atom[self.instance[1]] == 'C' and self.species.atom[self.instance[2]] == 'H': final_dist = 1.84 if self.species.atom[self.instance[0]] == 'O' and self.species.atom[self.instance[1]] == 'C' and self.species.atom[self.instance[2]] == 'O': final_dist = 2.04 #TODO: verify if this value is OK if self.species.atom[self.instance[0]] == 'C' and self.species.atom[self.instance[1]] == 'O' and self.species.atom[self.instance[2]] == 'C': final_dist = 2.04 #TODO: verify if this value is OK if self.species.atom[self.instance[0]] == 'C' and self.species.atom[self.instance[1]] == 'O' and self.species.atom[self.instance[2]] == 'H': final_dist = 1.42 if self.species.atom[self.instance[0]] == 'C' and self.species.atom[self.instance[1]] == 'O' and self.species.atom[self.instance[2]] == 'O': final_dist = 2.04 #TODO: verify if this value is OK if self.species.atom[self.instance[0]] == 'O' and self.species.atom[self.instance[1]] == 'O' and self.species.atom[self.instance[2]] == 'C': final_dist = 2.04 #TODO: verify if this value is OK val = geometry.new_bond_length(self.species,self.instance[1],self.instance[2],step,12,final_dist,geom) constraint = [self.instance[1] + 1,self.instance[2] + 1,val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def __init__(self, species, qc, par, instance, instance_name): #st_pt of the reactant self.species = species #st_pt of the ts self.ts = None #st_pt of the product(s) self.products = [] #bond matrix of the products self.product_bonds = [] #optimization objects self.ts_opt = None self.prod_opt = [] self.qc = qc self.par = par #indices of the reactive atoms self.instance = instance #name of the reaction self.instance_name = instance_name #maximum number of steps for this reaction family self.max_step = 22 #do a scan? self.scan = 0 #skip the first 12 steps in case the instance has a length of 3? self.skip = 0 def get_constraints(self, step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i + 1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i + 1, j + 1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12) for dih in range(len(self.instance) - 3): constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) elif step < 22: for dih in range(len(self.instance) - 3): constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) release.append(constraint) fval = 1.35 val = geometry.new_bond_length(self.species, self.instance[0], self.instance[-1], step - 11, 10, fval, geom) constraint = [self.instance[0] + 1, self.instance[-1] + 1, val] change.append(constraint) val = geometry.new_bond_length(self.species, self.instance[-2], self.instance[-1], step - 11, 10, fval, geom) constraint = [self.instance[-2] + 1, self.instance[-1] + 1, val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i, fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self, step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i + 1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i + 1, j + 1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12) for dih in range(len(self.instance) - 3): constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) elif step < 22: for dih in range(1, len(self.instance) - 3): constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) release.append(constraint) first_dih = [self.instance[i] + 1 for i in range(4)] if step < 18: # make sure that the forming double bond stays in trans instead of moving to cis fix.append(first_dih) else: release.append(first_dih) fval = 2.2 val = geometry.new_bond_length(self.species, self.instance[0], self.instance[-1], step - 11, 10, fval, geom) constraint = [self.instance[0] + 1, self.instance[-1] + 1, val] change.append(constraint) fval = 1.8 val = geometry.new_bond_length(self.species, self.instance[-2], self.instance[3], step - 11, 10, fval, geom) constraint = [self.instance[-2] + 1, self.instance[3] + 1, val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i, fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release step += submit_qc(self.instance_name, 0) return step
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12) for dih in range(len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) elif step < 22: for dih in range(1,len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) release.append(constraint) first_dih = [ self.instance[i]+1 for i in range(4)] if step < 18: # make sure that the forming double bond stays in trans instead of moving to cis fix.append(first_dih) else: release.append(first_dih) fval = 2.2 val = geometry.new_bond_length(self.species,self.instance[0],self.instance[-1],step-11,10,fval,geom) constraint = [self.instance[0] + 1,self.instance[-1] + 1,val] change.append(constraint) fval = 1.8 val = geometry.new_bond_length(self.species,self.instance[-2],self.instance[3],step-11,10,fval,geom) constraint = [self.instance[-2] + 1,self.instance[3] + 1,val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release step += submit_qc(self.instance_name, 0) return step
def __init__(self,species,qc,par,instance,instance_name): #st_pt of the reactant self.species = species #st_pt of the ts self.ts = None #st_pt of the product(s) self.products = [] #bond matrix of the products self.product_bonds = [] #optimization objects self.ts_opt = None self.prod_opt = [] self.qc = qc self.par = par #indices of the reactive atoms self.instance = instance #name of the reaction self.instance_name = instance_name #maximum number of steps for this reaction family self.max_step = 22 #do a scan? self.scan = 0 #skip the first 12 steps in case the instance has a length of 3? self.skip = 0 def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12) for dih in range(len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) elif step < 22: for dih in range(len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) release.append(constraint) fval = 1.35 val = geometry.new_bond_length(self.species,self.instance[0],self.instance[-1],step-11,10,fval,geom) constraint = [self.instance[0] + 1,self.instance[-1] + 1,val] change.append(constraint) val = geometry.new_bond_length(self.species,self.instance[-2],self.instance[-1],step-11,10,fval,geom) constraint = [self.instance[-2] + 1,self.instance[-1] + 1,val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: if step < 10: dih = geometry.calc_dihedral(geom[self.instance[-4]], geom[self.instance[-3]], geom[self.instance[-2]], geom[self.instance[-1]])[0] if np.abs(dih) < 160: #move the dihedral to 160 degrees in 10 steps frac = 1. / (10 - step + 0.) new_dih = dih + frac * (160. - dih) constraint = [self.instance[-4] + 1,self.instance[-3] + 1,self.instance[-2] + 1,self.instance[-1] + 1,new_dih] change.append(constraint) fval = [2.0,2.0,1.8,1.8] if self.species.atom[self.instance[-1]] == 'H': fval[2] = 1.35 fval[3] = 1.35 val = geometry.new_bond_length(self.species,self.instance[0],self.instance[1],step+1,12,fval[0],geom) constraint = [self.instance[0] + 1,self.instance[1] + 1,val] change.append(constraint) val = geometry.new_bond_length(self.species,self.instance[2],self.instance[3],step+1,12,fval[1],geom) constraint = [self.instance[2] + 1,self.instance[3] + 1,val] change.append(constraint) if self.species.bond[self.instance[-1]][self.instance[-2]] == 1: val = geometry.new_bond_length(self.species,self.instance[-1],self.instance[-2],step+1,12,fval[2],geom) constraint = [self.instance[-1] + 1,self.instance[-2] + 1,val] change.append(constraint) #else do not change this bond length, the bond needs to stay and just change in order val = geometry.new_bond_length(self.species,self.instance[-1],self.instance[3],step+1,12,fval[3],geom) constraint = [self.instance[-1] + 1,self.instance[3] + 1,val] #todo: larger rings, this only work for 5 membered rings change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self, step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i + 1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i + 1, j + 1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12, geom) for dih in range(len(self.instance) - 4): # do not include last atom constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) ldih = [ ] # constraint for the last dihedral, which needs to be 180 degrees for i in range(4): ldih.append(self.instance[len(self.instance) - 4 + i] + 1) dih = geometry.calc_dihedral(geom[ldih[0] - 1], geom[ldih[1] - 1], geom[ldih[2] - 1], geom[ldih[3] - 1])[0] frac = 1. / (12. - step) if dih < 0: new_dih = dih - frac * (180. + dih) ldih.append(new_dih) else: new_dih = dih + frac * (180. - dih) ldih.append(new_dih) change.append(ldih) elif step < 22: for dih in range(len(self.instance) - 3): constraint = [] for i in range(4): constraint.append(self.instance[dih + i] + 1) release.append(constraint) fdist1 = constants.st_bond[''.join( sorted(self.species.atom[self.instance[0]] + self.species.atom[self.instance[-2]]))] * 1.0 if ''.join( sorted(self.species.atom[self.instance[0]] + self.species.atom[self.instance[-2]])) == 'CO': fdist1 = 1.68 ndist1 = geometry.new_bond_length(self.species, self.instance[0], self.instance[-2], step - 11, 10, fdist1, geom) constraint = [self.instance[0] + 1, self.instance[-2] + 1, ndist1] change.append(constraint) fdist2 = constants.st_bond[''.join( sorted(self.species.atom[self.instance[-1]] + self.species.atom[self.instance[-2]]))] * 1.0 if ''.join( sorted(self.species.atom[self.instance[-1]] + self.species.atom[self.instance[-2]])) == 'CO': fdist2 = 1.68 ndist2 = geometry.new_bond_length(self.species, self.instance[-1], self.instance[-2], step - 11, 10, fdist2, geom) constraint = [self.instance[-1] + 1, self.instance[-2] + 1, ndist2] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i, fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self, step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i + 1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i + 1, j + 1]) if step == 0: # verify if the radical atom has more than one neighbor and # change the dihedral to 90 degrees in that case neigh = [ i for i, ni in enumerate(self.species.bond[self.instance[0]]) if ni > 0 ] if len(neigh) > 1: for ni in neigh: if not ni in self.instance: change.append([ ni + 1, self.instance[0] + 1, self.instance[1] + 1, self.instance[2] + 1, 90. ]) break if step < self.max_step: final_dist = 1.42 if self.species.atom[ self.instance[0]] == 'C' and self.species.atom[ self.instance[1]] == 'C' and self.species.atom[ self.instance[2]] == 'C': final_dist = 1.6 if self.species.atom[ self.instance[0]] == 'C' and self.species.atom[ self.instance[1]] == 'C' and self.species.atom[ self.instance[2]] == 'H': final_dist = 1.6 if self.species.atom[ self.instance[0]] == 'C' and self.species.atom[ self.instance[1]] == 'C' and self.species.atom[ self.instance[2]] == 'O': final_dist = 1.6 if self.species.atom[ self.instance[0]] == 'O' and self.species.atom[ self.instance[1]] == 'C' and self.species.atom[ self.instance[2]] == 'C': final_dist = 1.6 if self.species.atom[ self.instance[0]] == 'O' and self.species.atom[ self.instance[1]] == 'C' and self.species.atom[ self.instance[2]] == 'H': final_dist = 1.6 if self.species.atom[ self.instance[0]] == 'O' and self.species.atom[ self.instance[1]] == 'C' and self.species.atom[ self.instance[2]] == 'O': final_dist = 1.6 #TODO: verify if this value is OK if self.species.atom[ self.instance[0]] == 'C' and self.species.atom[ self.instance[1]] == 'O' and self.species.atom[ self.instance[2]] == 'C': final_dist = 1.6 #TODO: verify if this value is OK if self.species.atom[ self.instance[0]] == 'C' and self.species.atom[ self.instance[1]] == 'O' and self.species.atom[ self.instance[2]] == 'H': final_dist = 1.6 if self.species.atom[ self.instance[0]] == 'C' and self.species.atom[ self.instance[1]] == 'O' and self.species.atom[ self.instance[2]] == 'O': final_dist = 1.6 #TODO: verify if this value is OK if self.species.atom[ self.instance[0]] == 'O' and self.species.atom[ self.instance[1]] == 'O' and self.species.atom[ self.instance[2]] == 'C': final_dist = 1.6 #TODO: verify if this value is OK val = geometry.new_bond_length(self.species, self.instance[1], self.instance[2], step, self.max_step, final_dist, geom) constraint = [self.instance[1] + 1, self.instance[2] + 1, val] change.append(constraint) # breaking the delta bond final_dist = 1.7 # this might need to be refined val = geometry.new_bond_length(self.species, self.instance[3], self.instance[4], step, self.max_step, final_dist, geom) constraint = [self.instance[3] + 1, self.instance[4] + 1, val] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i, fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release
def get_constraints(self,step, geom): """ There are three types of constraints: 1. fix a coordinate to the current value 2. change a coordinate and fix is to the new value 3. release a coordinate (only for gaussian) """ fix = [] change = [] release = [] if step < self.max_step: #fix all the bond lengths for i in range(self.species.natom - 1): for j in range(i+1, self.species.natom): if self.species.bond[i][j] > 0: fix.append([i+1,j+1]) if step < 12: new_dihs = geometry.new_ring_dihedrals(self.species, self.instance, step, 12,geom) for dih in range(len(self.instance)-4): # do not include last atom constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) constraint.append(new_dihs[dih]) change.append(constraint) ldih = [] # constraint for the last dihedral, which needs to be 180 degrees for i in range(4): ldih.append(self.instance[len(self.instance)-4+i] + 1) dih = geometry.calc_dihedral(geom[ldih[0] - 1], geom[ldih[1] - 1], geom[ldih[2] - 1], geom[ldih[3] - 1])[0] frac = 1./(12. - step) if dih < 0: new_dih = dih - frac * (180. + dih) ldih.append(new_dih) else: new_dih = dih + frac * (180. - dih) ldih.append(new_dih) change.append(ldih) elif step < 22: for dih in range(len(self.instance)-3): constraint = [] for i in range(4): constraint.append(self.instance[dih+i] + 1) release.append(constraint) fdist1 = constants.st_bond[''.join(sorted(self.species.atom[self.instance[0]]+self.species.atom[self.instance[-2]]))]*1.0 if ''.join(sorted(self.species.atom[self.instance[0]]+self.species.atom[self.instance[-2]])) == 'CO': fdist1 = 1.68 ndist1 = geometry.new_bond_length(self.species,self.instance[0],self.instance[-2],step - 11 ,10,fdist1,geom) constraint = [self.instance[0] + 1,self.instance[-2] + 1,ndist1] change.append(constraint) fdist2 = constants.st_bond[''.join(sorted(self.species.atom[self.instance[-1]]+self.species.atom[self.instance[-2]]))]*1.0 if ''.join(sorted(self.species.atom[self.instance[-1]]+self.species.atom[self.instance[-2]])) == 'CO': fdist2 = 1.68 ndist2 = geometry.new_bond_length(self.species,self.instance[-1],self.instance[-2],step - 11 ,10,fdist2,geom) constraint = [self.instance[-1] + 1,self.instance[-2] + 1,ndist2] change.append(constraint) #remove the bonds from the fix if they are in another constaint for c in change: if len(c) == 3: index = -1 for i,fi in enumerate(fix): if len(fi) == 2: if sorted(fi) == sorted(c[:2]): index = i if index > -1: del fix[index] return step, fix, change, release