1 | import pyMoleCuilder
|
---|
2 | import os, sys, csv
|
---|
3 |
|
---|
4 | # check arguments
|
---|
5 | if len(sys.argv) < 8:
|
---|
6 | sys.stderr.write("Usage: "+sys.argv[0]+" <source file> <steps> <basis> <theory> <server> <port> <workdir> <energyfile> <conformationfile>\n")
|
---|
7 | sys.exit(255)
|
---|
8 |
|
---|
9 | order=4
|
---|
10 | sourcefile=sys.argv[1]
|
---|
11 | steps=int(sys.argv[2])
|
---|
12 | basis=sys.argv[3]
|
---|
13 | theory=sys.argv[4]
|
---|
14 | serveraddress=sys.argv[5]
|
---|
15 | serverport=sys.argv[6]
|
---|
16 | workdir=sys.argv[7]
|
---|
17 | energyfile=sys.argv[8]
|
---|
18 | conformationfile=""
|
---|
19 | if len(sys.argv) >= 9:
|
---|
20 | conformationfile=sys.argv[9]
|
---|
21 |
|
---|
22 | # ========================== Stored Session BEGIN ==========================
|
---|
23 | pyMoleCuilder.MoleculeLoad(sourcefile)
|
---|
24 | pyMoleCuilder.ParserSetParserParameters(set_parser_parameters="mpqc", parser_parameters="basis="+basis+";theory="+theory+";do_gradient=no;")
|
---|
25 | energies={}
|
---|
26 | stepwidth=int(360/steps)
|
---|
27 | for step in range(0,360,stepwidth):
|
---|
28 | pyMoleCuilder.wait()
|
---|
29 | # calculate energy
|
---|
30 | pyMoleCuilder.SelectionAllAtoms()
|
---|
31 | pyMoleCuilder.FragmentationFragmentation(fragment_molecule="BondFragment", distance="3", order=str(order), DoSaturate="1", ExcludeHydrogen="1", output_types="", max_meshwidth="0", grid_level="5", inter_order="0", DoCyclesFull="0", parse_state_files="0")
|
---|
32 | pyMoleCuilder.FragmentationFragmentationAutomation(server_address=serveraddress, server_port=serverport, fragment_executable="", max_meshwidth="0", grid_level="5", near_field_cells="3", interpolation_degree="3", DoLongrange="0", DoValenceOnly="0", DoPrintDebug="0", DoSmearElectronicCharges="0", UseImplicitCharges="0")
|
---|
33 | pyMoleCuilder.FragmentationAnalyseFragmentationResults(store_grids="0", fragment_prefix="BondFragment", UseImplicitCharges="0")
|
---|
34 | # extract energy and place in hash map
|
---|
35 | pyMoleCuilder.wait()
|
---|
36 | with open(workdir+"/BondFragment_Energy.dat", 'rb') as csvfile:
|
---|
37 | energyreader = csv.reader(csvfile, delimiter='\t', quotechar='|')
|
---|
38 | for row in energyreader:
|
---|
39 | if (row[0]==str(order)):
|
---|
40 | energies[step]=row[1]
|
---|
41 | break
|
---|
42 | # select bond
|
---|
43 | pyMoleCuilder.SelectionClearAllAtoms()
|
---|
44 | pyMoleCuilder.SelectionAtomById("0")
|
---|
45 | pyMoleCuilder.SelectionAtomById("1")
|
---|
46 | # advance to next time step
|
---|
47 | pyMoleCuilder.WorldStepWorldTime("1")
|
---|
48 | # rotate bond
|
---|
49 | pyMoleCuilder.MoleculeRotateAroundBond(str(stepwidth), "1")
|
---|
50 | # output all
|
---|
51 | pyMoleCuilder.ParserSetOutputFormats("tremolo")
|
---|
52 | pyMoleCuilder.ParserSetTremoloAtomdata(set_tremolo_atomdata="Id type x=3 u=3 F=3 neighbors=4", reset="1")
|
---|
53 | if len(conformationfile) != 0:
|
---|
54 | pyMoleCuilder.WorldOutputAs(conformationfile)
|
---|
55 | # save energies as csv
|
---|
56 | with open(energyfile, 'wb') as csvfile:
|
---|
57 | energywriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
---|
58 | energywriter.writerow(["step", "energy"])
|
---|
59 | for key in sorted(energies.keys()):
|
---|
60 | energywriter.writerow([str(key), str(energies[key])])
|
---|
61 | # =========================== Stored Session END ===========================
|
---|
62 |
|
---|
63 | sys.exit(0)
|
---|