~sfiorucci/ptools/test_seb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// $Id$
//
// C++ Implementation: atomselection
//
// Description:
//
//

#include "atomselection.h"
#include <algorithm> //required for set_union|intersection


namespace PTools {

AtomSelection::AtomSelection(const Rigidbody& rigid)
{
    m_rigid=&rigid;
    for (uint i=0; i < rigid.Size(); i++)
    {
        this->AddAtomIndex(i);
    }
}


AtomSelection::~AtomSelection()
{
}

AtomSelection::AtomSelection(const AtomSelection& oldsel)
{
    this->m_rigid = oldsel.m_rigid;
    this->m_list = oldsel.m_list;
}



Rigidbody AtomSelection::CreateRigid()
{
    Rigidbody newrigid;
    for (uint i=0; i<this->Size(); i++)
    {
        Atom at = m_rigid->CopyAtom(m_list[i]);
        newrigid.AddAtom(at);
    }

    return newrigid;
}

AtomSelection AtomSelection::non(const AtomSelection& atsel)
{
return !atsel;
}

AtomSelection operator& (const AtomSelection& atsel1,const  AtomSelection& atsel2)
{
    AtomSelection selout;
    if (atsel1.m_rigid != atsel2.m_rigid)
    {
        selout.m_rigid=0;
        std::cout << "Warning: tring to find the intersection of two different rigidbody" << std::endl;
        return selout;
    }
    //else:

    selout.m_rigid = atsel1.m_rigid;
    set_intersection(atsel1.m_list.begin(), atsel1.m_list.end(),
                     atsel2.m_list.begin(), atsel2.m_list.end(), back_inserter(selout.m_list));

    return selout;
}



AtomSelection operator| (const AtomSelection& atsel1,const AtomSelection& atsel2)
{
    AtomSelection selout;
    AtomSelection cpatsel1(atsel1); //makes a copy of atsel1
    AtomSelection cpatsel2(atsel2); // makes a copy of atsel2

    if (atsel1.m_rigid != atsel2.m_rigid)
    {
        selout.m_rigid=0;
        std::cout<<"Warning: for now you should not make union of two different rigidbody this way!" << std::endl;
        return selout;
    }
    //else:
    selout.m_rigid = atsel1.m_rigid;
    sort(cpatsel1.m_list.begin(), cpatsel1.m_list.end());
    sort(cpatsel2.m_list.begin(), cpatsel2.m_list.end());
    set_union(cpatsel1.m_list.begin(), cpatsel1.m_list.end(),
              cpatsel2.m_list.begin(), cpatsel2.m_list.end(), back_inserter(selout.m_list));

    std::vector<uint> list2;
    unique_copy(selout.m_list.begin(),selout.m_list.end(),back_inserter(list2));
    swap(selout.m_list, list2);

    return selout;
}


AtomSelection operator! (const AtomSelection& seltoinverse)
{
      //TODO: tests!
      AtomSelection selout;
      selout.SetRigid(*seltoinverse.m_rigid);
      AtomSelection all = seltoinverse.m_rigid->SelectAllAtoms();
      set_difference(all.m_list.begin(), all.m_list.end(),
                     seltoinverse.m_list.begin(), seltoinverse.m_list.end(),
                     back_inserter(selout.m_list));

      return selout;
}

}