@@ -30,23 +30,44 @@ int colvar::coordnum::init(std::string const &conf)
3030 int error_code = cvc::init (conf);
3131
3232 group1 = parse_group (conf, " group1" );
33- group2 = parse_group (conf, " group2" );
3433
35- if (!group1 || !group2 ) {
34+ if (!group1) {
3635 return error_code | COLVARS_INPUT_ERROR;
3736 }
3837
39- if (int atom_number = cvm::atom_group::overlap (*group1, *group2)) {
40- error_code |= cvm::error (
41- " Error: group1 and group2 share a common atom (number: " + cvm::to_str (atom_number) + " )\n " ,
42- COLVARS_INPUT_ERROR);
38+ if (group1->b_dummy ) {
39+ error_code |= cvm::error (" Error: group1 may not be a dummy atom\n " , COLVARS_INPUT_ERROR);
4340 }
4441
45- if (group1->b_dummy ) {
46- error_code |=
47- cvm::error (" Error: only group2 is allowed to be a dummy atom\n " , COLVARS_INPUT_ERROR);
42+ if (function_type () != " selfCoordNum" ) {
43+
44+ group2 = parse_group (conf, " group2" );
45+ if (!group2) {
46+ return error_code | COLVARS_INPUT_ERROR;
47+ }
48+
49+ if (int atom_number = cvm::atom_group::overlap (*group1, *group2)) {
50+ error_code |= cvm::error (" Error: group1 and group2 share a common atom (number: " +
51+ cvm::to_str (atom_number) + " )\n " ,
52+ COLVARS_INPUT_ERROR);
53+ }
54+
55+ get_keyval (conf, " group2CenterOnly" , b_group2_center_only, group2->b_dummy );
56+
57+ if (b_group2_center_only) {
58+ num_pairs = group1->size ();
59+ } else {
60+ num_pairs = group1->size () * group2->size ();
61+ }
62+
63+ } else {
64+
65+ // selfCoordNum case
66+ num_pairs = (group1->size () * (group1->size () - 1 )) / 2 ;
4867 }
4968
69+ init_scalar_boundaries (0.0 , num_pairs);
70+
5071 // Get the default value from r0_vec to report it
5172 cvm::real r0 = r0_vec[0 ];
5273 bool const b_redefined_cutoff = get_keyval (conf, " cutoff" , r0, r0);
@@ -85,8 +106,6 @@ int colvar::coordnum::init(std::string const &conf)
85106 cvm::log (" Warning: only minimum-image distances are used by this variable.\n " );
86107 }
87108
88- get_keyval (conf, " group2CenterOnly" , b_group2_center_only, group2->b_dummy );
89-
90109 get_keyval (conf, " tolerance" , tolerance, tolerance);
91110 if (tolerance > 0 ) {
92111 cvm::main ()->cite_feature (" coordNum pairlist" );
@@ -96,21 +115,10 @@ int colvar::coordnum::init(std::string const &conf)
96115 COLVARS_INPUT_ERROR);
97116 // return and do not allocate the pairlists below
98117 }
99- size_t n;
100- if (b_group2_center_only) {
101- n = group1->size ();
102- } else {
103- n = group1->size () * group2->size ();
104- }
105- pairlist = new bool [n];
106- for (size_t i = 0 ; i < n; i++) pairlist[i] = true ;
118+ pairlist = new bool [num_pairs];
119+ for (size_t i = 0 ; i < num_pairs; i++) pairlist[i] = true ;
107120 }
108121
109- init_scalar_boundaries (0.0 , b_group2_center_only ?
110- static_cast <cvm::real>(group1->size ()) :
111- static_cast <cvm::real>(group1->size () *
112- group2->size ()));
113-
114122 return error_code;
115123}
116124
@@ -376,68 +384,6 @@ void colvar::h_bond::calc_gradients()
376384colvar::selfcoordnum::selfcoordnum ()
377385{
378386 set_function_type (" selfCoordNum" );
379- x.type (colvarvalue::type_scalar);
380- cvm::real const r0 = cvm::main ()->proxy ->angstrom_to_internal (4.0 );
381- r0_vec = {r0, r0, r0};
382- }
383-
384-
385- int colvar::selfcoordnum::init (std::string const &conf)
386- {
387- int error_code = cvc::init (conf);
388-
389- group1 = parse_group (conf, " group1" );
390-
391- if (!group1 || group1->size () == 0 ) {
392- return error_code | COLVARS_INPUT_ERROR;
393- }
394-
395- cvm::real r0 = r0_vec[0 ];
396- bool const b_redefined_cutoff = get_keyval (conf, " cutoff" , r0, r0);
397- if (b_redefined_cutoff) {
398- r0_vec = {r0, r0, r0};
399- }
400- get_keyval (conf, " expNumer" , en, en);
401- get_keyval (conf, " expDenom" , ed, ed);
402-
403-
404- if ((en % 2 ) || (ed % 2 )) {
405- error_code |= cvm::error (" Error: odd exponent(s) provided, can only use even ones.\n " ,
406- COLVARS_INPUT_ERROR);
407- }
408-
409- if ((en <= 0 ) || (ed <= 0 )) {
410- error_code |= cvm::error (" Error: negative exponent(s) provided.\n " , COLVARS_INPUT_ERROR);
411- }
412-
413- if (!is_enabled (f_cvc_pbc_minimum_image)) {
414- cvm::log (" Warning: only minimum-image distances are used by this variable.\n " );
415- }
416-
417- get_keyval (conf, " tolerance" , tolerance, tolerance);
418- if (tolerance > 0 ) {
419- get_keyval (conf, " pairListFrequency" , pairlist_freq, pairlist_freq);
420- if ( ! (pairlist_freq > 0 ) ) {
421- error_code |= cvm::error (" Error: non-positive pairlistfrequency provided.\n " ,
422- COLVARS_INPUT_ERROR);
423- }
424- size_t n = (group1->size ()-1 ) * (group1->size ()-1 );
425- pairlist = new bool [n];
426- for (size_t i = 0 ; i < n; i++) pairlist[i] = true ;
427- }
428-
429- init_scalar_boundaries (0.0 , static_cast <cvm::real>((group1->size ()-1 ) *
430- (group1->size ()-1 )));
431-
432- return error_code;
433- }
434-
435-
436- colvar::selfcoordnum::~selfcoordnum ()
437- {
438- if (pairlist) {
439- delete [] pairlist;
440- }
441387}
442388
443389
0 commit comments