예제 #1
0
def outputMolecule(singleMol, dataDir):
    molecule = Molecule([], [])
    for site in singleMol:
        molecule.append(str(site.specie), site.coords)
    xyzObj = XYZ(molecule)
    os.chdir(dataDir)
    os.system('mkdir singleMolecule')
    xyzObj.write_file(dataDir + '/singleMolecule/singleMol.xyz')
예제 #2
0
def outputMolecule(singleMol, dataDir):
    molecule = Molecule([], [])
    singlemolpath = os.path.join(dataDir, 'singlemolecule')
    for siteIndex in singleMol.keys():
        molecule.append(str(singleMol[siteIndex].specie), singleMol[siteIndex].coords)
    xyzObj = XYZ(molecule)
    if "singleMol.xyz" in os.listdir(singlemolpath):
        decision = None
        print('You have one \'singleMol.xyz\' file inside the single molecule path.')
        print('This previous file will be overwritten.')
        while decision != 'Y' and decision != 'N':
            decision = input('Do you want to proceed? Y for yes, N for no.')
            if decision == 'Y':
                xyzObj.write_file(os.path.join(singlemolpath, 'singleMol.xyz'))
                print('The single molecule structure is saved under:', os.path.join(dataDir, 'singlemolecule.singleMol.xyz'))
            elif decision == 'N':
                print('The previous file is not changed. ')
                sys.exit()
            else:
                print('Not eligible response!!!\n')
    else:
        xyzObj.write_file(os.path.join(singlemolpath, 'singleMol.xyz'))
        print('The single molecule structure is saved under:', os.path.join(dataDir, 'singlemolecule/singleMol.xyz'))
예제 #3
0
 def test_expand_structure(self):
     molecule = ColorVonoroi.expand_structure(self.struc)
     xyz = XYZ(molecule)
     xyz.write_file(
         "/Users/yao/Google Drive/mmtools/data/expaned_structure.xyz")
예제 #4
0
mol = Molecule(["C", "H", "H", "H", "H"], coords)
print("mol:", mol)
print("\n")

print("mol[0]:", mol[0])
print("mol[1]:", mol[1])
print("\n")

#断连index为0和1两个原子之间的化学键,有上面的输出可以看到这两个位c和H,但是很奇怪为何会出现如下的结果?可能与空间结构有关系?
for frag in mol.break_bond(0, 1):
    print("frag:", frag)
print("\n")

print("neighbors of mol[0]:", mol.get_neighbors(mol[0], 3))
#得到分子中的共价键
print("covalent_bonds of:", mol.get_covalent_bonds())
print("\n")

#Creates a Structure from a Molecule by putting the Molecule in
#the center of a orthorhombic box. Useful for creating Structure
#for calculating molecules using periodic codes.
#通过把分子放在正交晶(orthorhombic)的盒子box里,从分子Molecule生存结构Structure。
#创建结构Structure,用于通过周期代码计算分子。
structure = mol.get_boxed_structure(10, 10, 10)
print("structure:", structure)

#xyz format是用来表示分子几何结构的文件,需要定分子中原子的坐标。
from pymatgen.io.xyz import XYZ
xyz = XYZ(mol)
xyz.write_file("methane.xyz")