Changeset dbe929
- Timestamp:
- Apr 25, 2008, 1:54:51 PM (17 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- cf959d
- Parents:
- 7151c4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/builder.cpp
r7151c4 rdbe929 683 683 }; 684 684 685 /** Tries given filename or standard on saving the config file. 686 * \param *ConfigFileName name of file 687 * \param *configuration pointer to configuration structure with all the values 688 * \param *periode pointer to periodentafel structure with all the elements 689 * \param *mol pointer to molecule structure with all the atoms and coordinates 690 */ 691 void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol) 692 { 693 char filename[255]; 694 ofstream output; 695 696 // get correct valence orbitals 697 mol->CalculateOrbitals(*configuration); 698 configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble; 699 if (ConfigFileName != NULL) 700 output.open(ConfigFileName, ios::trunc); 701 if (output == NULL) 702 output.open("main_pcp_linux", ios::trunc); 703 if (configuration->Save(&output, periode, mol)) 704 cout << Verbose(0) << "Saving of config file successful." << endl; 705 else 706 cout << Verbose(0) << "Saving of config file failed." << endl; 707 output.close(); 708 output.clear(); 709 // and save to xyz file 710 if (ConfigFileName != NULL) { 711 strcpy(filename, ConfigFileName); 712 strcat(filename, ".xyz"); 713 output.open(filename, ios::trunc); 714 } 715 if (output == NULL) { 716 strcpy(filename,"main_pcp_linux"); 717 strcat(filename, ".xyz"); 718 output.open(filename, ios::trunc); 719 } 720 if (mol->OutputXYZ(&output)) 721 cout << Verbose(0) << "Saving of XYZ file successful." << endl; 722 else 723 cout << Verbose(0) << "Saving of XYZ file failed." << endl; 724 output.close(); 725 output.clear(); 726 }; 727 685 728 /********************************************** Main routine **************************************/ 686 729 687 730 int main(int argc, char **argv) 688 731 { 689 732 periodentafel *periode = new periodentafel; // and a period table of all elements 690 733 molecule *mol = new molecule(periode); // first we need an empty molecule 734 config configuration; 691 735 double tmp1; 692 736 double bond, min_bond; … … 697 741 double *factor; // unit factor if desired 698 742 bool valid; // flag if input was valid or not 699 config configuration;700 743 ifstream test; 701 744 ofstream output; 702 745 string line; 703 746 char filename[255]; 747 char *ConfigFileName = NULL; 704 748 int flag = 1; 705 749 int Z; … … 708 752 enum BondOrderScheme Scheme = NoScheme; 709 753 enum CutCyclicBond CutCyclic; 754 enum ConfigStatus config_present = absent; 710 755 MoleculeLeafClass *Subgraphs = NULL; 711 756 clock_t start,end; … … 713 758 vector **Vectors; 714 759 715 // Greetings716 cout << Verbose(0) << "Molecuilder v1" << endl << endl;717 cout << Verbose(0) << "Build your own molecule position set." << endl;718 719 760 // load element list 720 761 periode->LoadPeriodentafel(); … … 722 763 723 764 // parse config file if given 724 if (argc >= 2) { // config file specified as option 725 cout << Verbose(0) << "Config file given." << endl; 726 test.open(argv[1], ios::in); 727 if (test == NULL) { 728 cout << Verbose(1) << "Specified config file not found." << endl; 729 //return (1); 730 } else { 731 cout << Verbose(1) << "Specified config file found, parsing ..."; 732 switch (configuration.TestSyntax(&test, periode, mol)) { 733 case 1: 734 cout << "new syntax." << endl; 735 configuration.Load(&test, periode, mol); 736 break; 737 case 0: 738 cout << "old syntax." << endl; 739 configuration.LoadOld(&test, periode, mol); 740 break; 741 default: 742 cout << "unknown syntax or empty configuration file." << endl; 743 //return(1); 765 if (argc >= 1) { // config file specified as option 766 if (argv[argc-1][0] != '-') { 767 cout << Verbose(0) << "Config file given." << endl; 768 test.open(argv[argc-1], ios::in); 769 if (test == NULL) { 770 //return (1); 771 output.open(argv[argc-1], ios::out); 772 if (output == NULL) { 773 cout << Verbose(1) << "Specified config file " << argv[argc-1] << " not found." << endl; 774 config_present = absent; 775 } else { 776 cout << "Empty configuration file." << endl; 777 ConfigFileName = argv[argc-1]; 778 config_present = empty; 779 output.close(); 780 } 781 } else { 782 ConfigFileName = argv[argc-1]; 783 cout << Verbose(1) << "Specified config file found, parsing ..."; 784 switch (configuration.TestSyntax(&test, periode, mol)) { 785 case 1: 786 cout << "new syntax." << endl; 787 configuration.Load(&test, periode, mol); 788 config_present = present; 789 break; 790 case 0: 791 cout << "old syntax." << endl; 792 configuration.LoadOld(&test, periode, mol); 793 config_present = present; 794 break; 795 default: 796 cout << "Unknown syntax or empty, yet present file." << endl; 797 config_present = empty; 798 } 799 test.close(); 744 800 } 745 test.close();746 }747 }748 // command line stuff749 if (argc > 2) {750 cout << Verbose(0) << "Recognized command line argument: " << argv[2][1] << ".\n";751 switch(argv[2][1]) {752 case 't':753 cout << Verbose(1) << "Translating all ions to new origin." << endl;754 for (int i=0;i<3;i++)755 x.x[i] = atof(argv[3+i]);756 mol->Translate((const vector *)&x);757 break;758 case 'a':759 cout << Verbose(1) << "Adding new atom." << endl;760 first = new atom;761 for (int i=0;i<3;i++)762 first->x.x[i] = atof(argv[4+i]);763 finder = periode->start;764 while (finder != periode->end) {765 finder = finder->next;766 if (strncmp(finder->symbol,argv[3],3) == 0) {767 first->type = finder;801 } else 802 config_present = absent; 803 int argptr = 1; 804 do { 805 if (argv[argptr][0] == '-') { 806 cout << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n"; 807 argptr++; 808 switch(argv[argptr-1][1]) { 809 case 'h': 810 case 'H': 811 case '?': 812 cout << "MoleCuilder suite" << endl << "==================" << endl << endl; 813 cout << "Usage: " << argv[0] << "[-{acsthH?vfrp}] [further arguments] [config file]" << endl; 814 cout << "or simply " << argv[0] << " without arguments for interactive session." << endl; 815 cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl; 816 cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl; 817 cout << "\t-h/-H/-?\tGive this help screen." << endl; 818 cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl; 819 cout << "\t-r\t\tConvert file from an old pcp syntax." << endl; 820 cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl; 821 cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl; 822 cout << "\t-v/-V\t\tGives version information." << endl; 823 return 0; 768 824 break; 825 case 'v': 826 case 'V': 827 cout << argv[0] << " " << VERSIONSTRING << endl; 828 cout << "Build your own molecule position set." << endl; 829 return 0; 830 break; 831 default: 832 break; 833 } 834 if ((config_present == present) || (config_present == empty)) { 835 switch(argv[argptr-1][1]) { 836 case 'p': 837 cout << Verbose(1) << "Parsing xyz file for new atoms." << endl; 838 if (!mol->AddXYZFile(argv[argptr++])) 839 cout << Verbose(2) << "File not found." << endl; 840 else 841 cout << Verbose(2) << "File found and parsed." << endl; 842 break; 843 default: 844 break; 769 845 } 770 846 } 771 mol->AddAtom(first); // add to molecule 772 break; 773 case 's': 774 j = -1; 775 cout << Verbose(1) << "Scaling all ion positions by factor." << endl; 776 factor = (double *) Malloc(sizeof(double)*NDIM, "main: *factor"); 777 factor[0] = atof(argv[3]); 778 factor[1] = (argc >=4) ? atof(argv[4]) : atof(argv[3]); 779 factor[2] = (argc >=5) ? atof(argv[5]) : atof(argv[3]); 780 mol->Scale(&factor); 781 for (int i=0;i<3;i++) { 782 j += i+1; 783 x.x[i] = atof(argv[3+i]); 784 mol->cell_size[j]*=factor[i]; 847 if (config_present != empty) { 848 if (config_present == present) { 849 switch(argv[argptr-1][1]) { 850 case 't': 851 cout << Verbose(1) << "Translating all ions to new origin." << endl; 852 for (int i=0;i<3;i++) 853 x.x[i] = atof(argv[argptr+i]); 854 mol->Translate((const vector *)&x); 855 argptr+=3; 856 break; 857 case 'a': 858 cout << Verbose(1) << "Adding new atom." << endl; 859 first = new atom; 860 for (int i=0;i<3;i++) 861 first->x.x[i] = atof(argv[argptr+1+i]); 862 finder = periode->start; 863 while (finder != periode->end) { 864 finder = finder->next; 865 if (strncmp(finder->symbol,argv[argptr+1],3) == 0) { 866 first->type = finder; 867 break; 868 } 869 } 870 mol->AddAtom(first); // add to molecule 871 argptr+=4; 872 break; 873 case 's': 874 j = -1; 875 cout << Verbose(1) << "Scaling all ion positions by factor." << endl; 876 factor = (double *) Malloc(sizeof(double)*NDIM, "main: *factor"); 877 factor[0] = atof(argv[argptr]); 878 if (argc > argptr+1) 879 argptr++; 880 factor[1] = atof(argv[argptr]); 881 if (argc > argptr+1) 882 argptr++; 883 factor[2] = atof(argv[argptr]); 884 mol->Scale(&factor); 885 for (int i=0;i<3;i++) { 886 j += i+1; 887 x.x[i] = atof(argv[3+i]); 888 mol->cell_size[j]*=factor[i]; 889 } 890 Free((void **)&factor, "main: *factor"); 891 argptr+=1; 892 break; 893 case 'c': 894 j = -1; 895 cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl; 896 // make every coordinate positive 897 mol->CenterEdge((ofstream *)&cout, &x); 898 // update Box of atoms by boundary 899 mol->SetBoxDimension(&x); 900 // translate each coordinate by boundary 901 j=-1; 902 for (int i=0;i<3;i++) { 903 j += i+1; 904 x.x[i] = atof(argv[argptr++]); 905 mol->cell_size[j] += x.x[i]*2.; 906 } 907 mol->Translate((const vector *)&x); 908 break; 909 case 'r': 910 cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl; 911 break; 912 case 'f': 913 int i,j; 914 flag = 0; 915 if (argc > argptr+3) { 916 cout << Verbose(0) << "Creating connection matrix..." << endl; 917 start = clock(); 918 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++])); 919 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl; 920 cout << Verbose(0) << "What's the desired bond scheme [(B)ottomUp/(T)opDown/(A)NOVA/(C)ombined]: "; 921 CutCyclic = SaturateBond; 922 switch (argv[argptr+1][0]) { 923 default: 924 Scheme = NoScheme; 925 break; 926 case 'B': 927 CutCyclic = KeepBond; 928 case 'b': 929 Scheme = BottomUp; 930 i = atoi(argv[argptr]); 931 j = 0; 932 break; 933 case 'T': 934 CutCyclic = KeepBond; 935 case 't': 936 Scheme = TopDown; 937 i = 0; 938 j = atoi(argv[argptr]); 939 break; 940 case 'A': 941 CutCyclic = KeepBond; 942 case 'a': 943 Scheme = ANOVA; 944 i = atoi(argv[argptr]); 945 j = 0; 946 break; 947 // case 'C': 948 // CutCyclic = KeepBond; 949 // case 'c': 950 // if (argc > 5) { 951 // i = atoi(argv[4]); 952 // j = atoi(argv[6]); 953 // Scheme = Combined; 954 // } 955 // else 956 // cerr << "Missing second bond order for TopDown fragmentation in combined approach." << endl; 957 // break; 958 }; 959 if (mol->first->next != mol->last) { 960 mol->FragmentMolecule((ofstream *)&cout, i, j, Scheme, &configuration, CutCyclic); 961 } 962 end = clock(); 963 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; 964 argptr+=2; 965 } 966 break; 967 default: 968 break; 969 } 970 } else { 971 cout << "Cannot apply command line parameter as no valid config file was found." << endl; 972 return 1; 973 } 785 974 } 786 Free((void **)&factor, "main: *factor"); 787 break; 788 case 'c': 789 j = -1; 790 cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl; 791 // make every coordinate positive 792 mol->CenterEdge((ofstream *)&cout, &x); 793 // update Box of atoms by boundary 794 mol->SetBoxDimension(&x); 795 // translate each coordinate by boundary 796 j=-1; 797 for (int i=0;i<3;i++) { 798 j += i+1; 799 x.x[i] = atof(argv[3+i]); 800 mol->cell_size[j] += x.x[i]*2.; 801 } 802 mol->Translate((const vector *)&x); 803 break; 804 case 'r': 805 cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl; 806 break; 807 case 'p': 808 cout << Verbose(1) << "Parsing xyz file for new atoms." << endl; 809 if (!mol->AddXYZFile(argv[3])) 810 cout << Verbose(2) << "File not found." << endl; 811 else 812 cout << Verbose(2) << "File found and parsed." << endl; 813 break; 814 case 'f': 815 int i,j; 816 flag = 0; 817 if (argc > 4) { 818 cout << Verbose(0) << "Creating connection matrix..." << endl; 819 start = clock(); 820 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[3])); 821 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl; 822 cout << Verbose(0) << "What's the desired bond scheme [(B)ottomUp/(T)opDown/(A)NOVA/(C)ombined]: "; 823 CutCyclic = SaturateBond; 824 switch (argv[5][0]) { 825 default: 826 Scheme = NoScheme; 827 break; 828 case 'B': 829 CutCyclic = KeepBond; 830 case 'b': 831 Scheme = BottomUp; 832 i = atoi(argv[4]); 833 j = 0; 834 break; 835 case 'T': 836 CutCyclic = KeepBond; 837 case 't': 838 Scheme = TopDown; 839 i = 0; 840 j = atoi(argv[4]); 841 break; 842 case 'A': 843 CutCyclic = KeepBond; 844 case 'a': 845 Scheme = ANOVA; 846 i = atoi(argv[4]); 847 j = 0; 848 break; 849 case 'C': 850 CutCyclic = KeepBond; 851 case 'c': 852 if (argc > 5) { 853 i = atoi(argv[4]); 854 j = atoi(argv[6]); 855 Scheme = Combined; 856 } 857 else 858 cerr << "Missing second bond order for TopDown fragmentation in combined approach." << endl; 859 break; 860 }; 861 if (mol->first->next != mol->last) { 862 mol->FragmentMolecule((ofstream *)&cout, i, j, Scheme, &configuration, CutCyclic); 863 } 864 end = clock(); 865 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; 866 } 867 break; 868 default: 869 break; 870 } 871 if (flag) { 872 mol->CountElements(); // this is a bugfix, atoms should should actually be added correctly to this fragment 873 mol->CalculateOrbitals(configuration); 874 configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.MaxPsiDouble; 875 if (argc >= 1) 876 output.open(argv[1], ios::trunc); 877 if (!output) 878 output.open("main_pcp_linux", ios::trunc); 879 if (configuration.Save(&output, periode, mol)) 880 cout << Verbose(1) << "Saving of config file successful." << endl; 881 else 882 cout << Verbose(1) << "Saving of config file failed." << endl; 883 output.close(); 884 output.clear(); 885 // and save to xyz file 886 if (argc >= 1) { 887 strcpy(filename, argv[1]); 888 strcat(filename, ".xyz"); 889 output.open(filename, ios::trunc); 890 } 891 if (output == NULL) { 892 strcpy(filename,"main_pcp_linux"); 893 strcat(filename, ".xyz"); 894 output.open(filename, ios::trunc); 895 } 896 if (mol->OutputXYZ(&output)) 897 cout << Verbose(0) << "Saving of XYZ file successful." << endl; 898 else 899 cout << Verbose(0) << "Saving of XYZ file failed." << endl; 900 output.close(); 901 output.clear(); 902 } 975 } else argptr++; 976 } while (argptr < (argc-1)); 977 if (flag) 978 SaveConfig(ConfigFileName, &configuration, periode, mol); 903 979 delete(mol); 904 980 delete(periode); … … 1115 1191 1116 1192 case 's': // save to config file 1117 // get correct valence orbitals 1118 mol->CalculateOrbitals(configuration); 1119 configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.MaxPsiDouble; 1120 if (argc >= 1) 1121 output.open(argv[1], ios::trunc); 1122 if (output == NULL) 1123 output.open("main_pcp_linux", ios::trunc); 1124 if (configuration.Save(&output, periode, mol)) 1125 cout << Verbose(0) << "Saving of config file successful." << endl; 1126 else 1127 cout << Verbose(0) << "Saving of config file failed." << endl; 1128 output.close(); 1129 output.clear(); 1130 // and save to xyz file 1131 if (argc >= 1) { 1132 strcpy(filename, argv[1]); 1133 strcat(filename, ".xyz"); 1134 output.open(filename, ios::trunc); 1135 } 1136 if (output == NULL) { 1137 strcpy(filename,"main_pcp_linux"); 1138 strcat(filename, ".xyz"); 1139 output.open(filename, ios::trunc); 1140 } 1141 if (mol->OutputXYZ(&output)) 1142 cout << Verbose(0) << "Saving of XYZ file successful." << endl; 1143 else 1144 cout << Verbose(0) << "Saving of XYZ file failed." << endl; 1145 output.close(); 1146 output.clear(); 1193 SaveConfig(ConfigFileName, &configuration, periode, mol); 1147 1194 break; 1148 1195 };
Note:
See TracChangeset
for help on using the changeset viewer.