def fchkToGeom(filename): filename = filename.split('.fchk')[0] filename = filename.split('.fch')[0] fileobj = rxgau.GauFile(filename) fileobj.fchk.read() geom = rxmol.Molecule('mole') geom.addatomsFromLists(fileobj.fchk.atomnos, fileobj.fchk.atomcoords[-1])
def setUp(self): self.file = rxgau.GauFile("samples/testBmat") gAmber.GauAmberCOM(self.file) self.file.com.read() self.file.fchk.read() self.mole = rxmol.Molecule('12CH') self.mole.readfromxyz(self.file.com.xyz) self.mole.readconnectivity(self.file.com.connectivity)
def test_xyzfile(self): benzene = rxmol.Molecule("benzene") benfile = rxgau.GauFile("samples/bencom") benfile.fchk.read() benzene.addatomsFromLists(benfile.fchk.atomnos, benfile.fchk.atomcoords[-1]) self.assertEqual(benzene[1].name, 'C1') self.assertEqual(benzene[12].name, 'H12')
def testmmfile(self): mmfile = rxgau.GauFile('samples/mmfile') gAmber.GauAmberCOM(mmfile) mmfile.com.read() benmol = rxmol.Molecule('benzene') benmol.readfromxyz(mmfile.com.xyz) #benmol.readtypefromlist(mmfile.com.atomtypelist) #benmol.readchargefromlist(mmfile.com.atomchargelist) for atom in benmol: print(atom, atom.atomtype, atom.atomcharge) benmol.readconnectivity(mmfile.com.connectivity) print("Bond: ", len(benmol.bondlist.keys())) print("Angle: ", len(benmol.anglelist.keys())) print("Dihd: ", len(benmol.dihedrallist.keys()))
def setUp(self): self.mole = rxmol.Molecule("H2O2") self.assertTrue(isinstance(self.mole, rxmol.Molecule)) self.mole.addatom('O', np.array([0.0, 0.0, 0.0]), unit='angstrom') self.mole.addatom('H', np.array([0.0, 1.0, 0.0]), unit='angstrom') self.mole.addatom('O', np.array([0.0, 0.0, 1.0])) self.mole.addatom('H', np.array([1.0, 0.0, 0.0]), unit='angstrom') self.assertTrue(isinstance(self.mole[1], rxmol.Atom)) self.mole.addbond(1, 2) self.mole.addbond(1, 3) self.mole.addbond(3, 4) self.assertTrue(isinstance(self.mole.bond(1, 3), rxmol.Bond)) self.mole.addangle(2, 1, 3) self.mole.addangle(4, 3, 1) self.assertTrue(isinstance(self.mole.angle(2, 1, 3), rxmol.Angle)) self.mole.adddihedral(2, 1, 3, 4) self.assertTrue( isinstance(self.mole.dihedral(4, 3, 1, 2), rxmol.Dihedral)) self.assertEqual(self.mole.natom, 4) # def __iter__ ite = iter(self.mole) for atom in self.mole: print(atom.name) # def __next__ self.assertEqual(next(ite).name, 'O1') self.assertEqual(next(ite).name, 'H2') ite2 = iter(self.mole) self.assertEqual(next(ite2).name, 'O1') self.assertEqual(next(ite2).name, 'H2') self.assertEqual(next(ite).name, 'O3') self.assertEqual(next(ite).name, 'H4') self.assertEqual(next(ite2).name, 'O3') self.assertEqual(next(ite2).name, 'H4') # def __getitem__ self.assertEqual(str(self.mole[1].name), 'O1')
def test_readfile(self): benz = rxmol.Molecule("Benzene") with open('samples/ben.xyz', 'r') as f: f = f.read() benz.readfromxyz(f) self.assertEqual(benz[1].name, 'C1') self.assertEqual(benz[12].name, 'H12') #test_connty with open('samples/cnnty.com', 'r') as f: cn = f.read() benz.readconnectivity(cn) self.assertEqual(len(benz.bondlist.values()), 12) self.assertEqual(len(benz.anglelist.values()), 18) self.assertEqual(len(benz.dihedrallist.values()), 24) self.assertAlmostEqual(benz.angle(1, 2, 3).anglevalue, 120.00, delta=0.1) os.system( 'rm A* q* Q* p* esout *gaussian* samples/bencom.fchk samples/bencom.chk samples/bencom.log' )
import rxcclib.utils as utils import rxcclib.lazy as lazy import rxcclib.file.Gaussian as rxfile import rxcclib.geometry.molecules as rxmol with open('cnnty.com', 'r') as f: con = f.read() con = lazy.ConnectivityToConnectionMatrix(con) con = utils.LTMatrix.newFromUpperMat(con) benmol = rxmol.Molecule('ben') benfile = rxfile.GauFile('bencom') benfile.fchk.read() benmol.addatomsFromLists(benfile.fchk.atomnos, benfile.fchk.atomcoords[-1]) benmol.readConnectionMatrix(con.fullmat)
def readgeom(inputfile): # Read info from com mmcom = inputfile.com mole = rxmol.Molecule('thisgeometry') mmcom = GauAmberCOM(inputfile) mmcom.read() mole.readfromxyz(mmcom.xyz) mole.readchargefromlist(mmcom.atomchargelist) mole.readtypefromlist(mmcom.atomtypelist) mole.readconnectivity(mmcom.connectivity) for atom in mole: atom.vdwradius = float(mmcom.vdwdict[atom.atomtype][0]) atom.vdwwelldepth = float(mmcom.vdwdict[atom.atomtype][1]) # Store and count finalfunc finalfuncL = [] finalfuncL.extend(sorted(mmcom.bondfunc, key=lambda x: repr(x))) finalfuncL.extend(sorted(mmcom.anglefunc, key=lambda x: repr(x))) finalfuncL.extend(sorted(mmcom.dihdfunc, key=lambda x: repr(x))) finalfuncL.extend(sorted(mmcom.improperfunc, key=lambda x: repr(x))) for item in mmcom.improperfunc: for atom3 in mole: if atom3.atomtype == item.c: permu = itertools.permutations(atom3.neighbor, 3) res = [] for tu in permu: a = tu[0].atomtype == item.a or item.a == '*' b = tu[1].atomtype == item.b or item.b == '*' c = tu[2].atomtype == item.d or item.d == '*' if a and b and c: res.append([ tu[0].atomnum, tu[1].atomnum, atom3.atomnum, tu[2].atomnum ]) res = sorted(res, key=lambda x: (str(x[1]) + str(x[3]))) res = res[0] mole.addimproper(*res) # Match itnl and finalfunc itnlcordL = [] itnlcordL.extend(sorted(mole.dihedrallist.values(), key=lambda x: repr(x))) itnlcordL.extend(sorted(mole.anglelist.values(), key=lambda x: repr(x))) itnlcordL.extend(sorted(mole.bondlist.values(), key=lambda x: repr(x))) itnlcordL.extend(sorted(mole.improperlist.values(), key=lambda x: repr(x))) unkitnlL = [] knownitnlL = [] for item in itnlcordL: for func in finalfuncL: if matchitnlwithfinalfunc(item, func): item.func = func if type(item) is rxmol.Dihedral: item.dihdfunctions = copy.deepcopy(func.dihdfunctions) item.npaths = func.npaths elif type(item) is rxmol.Improper: item.forceconst = func.forceconst item.phase = func.phase item.periodicity = func.periodicity else: item.forceconst = func.forceconst item.eqvalue = func.eqvalue break return finalfuncL, itnlcordL, mole