示例#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 getAllMols(supercell, bondDict):
    # molList is the list of pymatgen Molecule object
    # tmpMol is pyatgen Molecule object
    molList = []
    while len(supercell.sites) != 0:
        # function getCentralSingleMol returns a dictionary
        # the keys are the index of each sites in supercell
        print('length of supercell:', len(supercell.sites))
        molsites = Molecule([], [])
        molindex = list()
        tmpMol = getCentralSingleMol(supercell, bondDict)
        for siteIndex in tmpMol.keys():
            molsites.append(str(tmpMol[siteIndex].specie),
                            tmpMol[siteIndex].coords)
            molindex.append(siteIndex)
        supercell.remove_sites(molindex)
        molList += [molsites]
    return molList
示例#3
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'))
示例#4
0
from pymatgen import Molecule
import os
import numpy as np

inpath = "./data/crystals"
namelist = os.listdir(inpath)
outpath = "./data/singmol"

nocando = []
for name in namelist:
    structID = name[:-3]
    print(structID)
    struct = read(os.path.join(inpath, name))
    struct = AseAtomsAdaptor.get_structure(struct)
    struct.make_supercell([4, 5, 7])
    bondDict = getBondDict(struct, bondCutoff)
    print(bondDict)
    try:
        singleMol = getCentralSingleMol(struct, bondDict)
        #singleMol.to(filename=outpath+"/"+structID+".xyz")
        mol = Molecule([], [])
        for site in singleMol.items():
            mol.append(str(site[1].specie), site[1].coords)
        mol.to(filename=outpath + "/" + structID + "xyz")
    except:
        nocando.append(structID)

print(nocando)
nocando = np.array(nocando)
np.savetxt('nocandolist.csv', nocando, delimiter=' ', fmt='%s')