本文整理汇总了Python中molecule.Molecule.add_bond方法的典型用法代码示例。如果您正苦于以下问题:Python Molecule.add_bond方法的具体用法?Python Molecule.add_bond怎么用?Python Molecule.add_bond使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类molecule.Molecule
的用法示例。
在下文中一共展示了Molecule.add_bond方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_cartesian
# 需要导入模块: from molecule import Molecule [as 别名]
# 或者: from molecule.Molecule import add_bond [as 别名]
class GeomReader:
def read_cartesian(self,fname):
molc=Molecule()
f = open(fname,'r')
while (True):
str = f.readline()
if (str==''):
break
sp = str.split()
if (len(sp) != 4):
continue
molc.add_atom(Atom(sp[0].lower(),0,float(sp[1]),float(sp[2]),float(sp[3])))
self.mol = molc
return molc
def read_zmatrix(self,fname):
f = open(fname,'r')
self.file = f;
name = f.readline().strip()
self.mol = Molecule()
self.mol.add_atom(Atom(name.lower(),1,0,0,0,connect=0));
str = f.readline();
sp = str.split();
if (sp == []):
return self.mol
sp[0] = sp[0].lower()
if (sp==[]):
return self.mol
try:
bl = float(sp[2])
except:
bl = self.lookup_var(sp[2])
self.mol.add_atom(Atom(sp[0],2,0,0,bl,int(sp[1])))
self.mol.add_bond(2,int(sp[1]))
str = f.readline();
sp = str.split();
if (sp == []):
return self.mol
sp[0] = sp[0].lower()
try:
bl = float(sp[2]);
except:
bl = self.lookup_var(sp[2])
try:
ba = float(sp[4]);
except:
ba = self.lookup_var(sp[4])
a = Atom(sp[0],3,math.sin(ba*math.pi/180.0)*bl,0,self.mol.atoms[int(sp[1]) -1].z - math.cos(ba*math.pi/180.0)*bl,int(sp[1]))# BIG CHANGE
self.mol.add_atom(a)
self.mol.add_bond(3,int(sp[1]))
atom_number = 4;
while (True):
#print atom_number
str = f.readline();
sp = str.split();
if (sp==[]):
print 'end of matrix'
break
sp[0] = sp[0].lower()
try:
bl = float(sp[2]);
except:
bl = self.lookup_var(sp[2])
try:
ba = float(sp[4]);
except:
ba = self.lookup_var(sp[4])
try:
dh = float(sp[6]);
except:
dh = self.lookup_var(sp[6])
connect = int(sp[1])
angle_connect = int(sp[3])
dihed_connect = int(sp[5])
atoms = self.mol.atoms;
#print 'connect: %i angle_connect: %i' %(connect,angle_connect)
vector1 = vec_minus(atoms[connect-1].xyz,atoms[angle_connect-1].xyz );
vector2 = vec_minus(atoms[connect-1].xyz,atoms[dihed_connect-1].xyz );
norm1 = vec_cross(vector1,vector2)
norm2 = vec_cross(vector1,norm1)
norm1 = normalise(norm1)
norm2 = normalise(norm2)
norm1 =vec_times(norm1,-1*math.sin(dh*math.pi/180))
norm2 = vec_times(norm2,math.cos(dh*math.pi/180))
vector3 =vec_add(norm1,norm2)
vector3 =normalise(vector3)
#.........这里部分代码省略.........